parent
faa7dc331d
commit
e8ac59ea84
@ -0,0 +1,26 @@ |
||||
package com.community.pocket.data.dao; |
||||
|
||||
import androidx.room.Dao; |
||||
import androidx.room.Delete; |
||||
import androidx.room.Insert; |
||||
import androidx.room.Query; |
||||
|
||||
import com.community.pocket.data.model.Token; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Dao |
||||
public interface TokenDao { |
||||
|
||||
@Query("select * from token") |
||||
List<Token> queryAll(); |
||||
|
||||
@Query("select * from token where token=:token") |
||||
Token query(String token); |
||||
|
||||
@Insert |
||||
void save(Token token); |
||||
|
||||
@Delete |
||||
void delete(Token user); |
||||
} |
@ -1,5 +1,9 @@ |
||||
package com.community.pocket.data.model; |
||||
|
||||
public abstract class AbstractForumHot { |
||||
abstract int getId(); |
||||
//排序值
|
||||
public abstract String orderValue(); |
||||
|
||||
//链接值
|
||||
public abstract String linkValue(); |
||||
} |
||||
|
@ -1,7 +1,40 @@ |
||||
package com.community.pocket.ui.main.ui.forum.hot; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.data.model.Hot; |
||||
import com.community.pocket.ui.main.ui.share.Response; |
||||
import com.community.pocket.ui.main.ui.share.ToastResponse; |
||||
import com.community.pocket.util.CustomMessage; |
||||
|
||||
public class ForumHotResponse extends Response<Hot> { |
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
/** |
||||
* 热榜信息响应体 |
||||
*/ |
||||
public class ForumHotResponse extends ToastResponse<ForumHotResponse.Msg> { |
||||
private Hot hot; |
||||
|
||||
public Hot getHot() { |
||||
return hot; |
||||
} |
||||
|
||||
public void setHot(Hot hot) { |
||||
this.hot = hot; |
||||
} |
||||
|
||||
enum Msg implements CustomMessage { |
||||
ok(R.string.load_hot_ok), |
||||
fail(R.string.load_hot_fail); |
||||
|
||||
private Integer msg; |
||||
|
||||
Msg(Integer msg) { |
||||
this.msg = msg; |
||||
} |
||||
|
||||
@NotNull |
||||
@Override |
||||
public Integer getMsg() { |
||||
return msg; |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,10 +1,45 @@ |
||||
package com.community.pocket.ui.main.ui.forum.main; |
||||
|
||||
import androidx.annotation.StringRes; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.data.model.Notice; |
||||
import com.community.pocket.ui.main.ui.share.Response; |
||||
import com.community.pocket.ui.main.ui.share.ToastResponse; |
||||
import com.community.pocket.util.CustomMessage; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ForumNoticeResponse extends Response<List<Notice>> { |
||||
/** |
||||
* 公告信息响应体 |
||||
*/ |
||||
public class ForumNoticeResponse extends ToastResponse<ForumNoticeResponse.Msg> { |
||||
|
||||
private List<Notice> noticeList; |
||||
|
||||
enum Msg implements CustomMessage { |
||||
ok(R.string.load_notice_ok), |
||||
fail(R.string.load_notice_fail); |
||||
|
||||
private Integer msg; |
||||
|
||||
Msg(@StringRes Integer msg) { |
||||
this.msg = msg; |
||||
} |
||||
|
||||
@NotNull |
||||
@Override |
||||
public Integer getMsg() { |
||||
return msg; |
||||
} |
||||
} |
||||
|
||||
public List<Notice> getNoticeList() { |
||||
return noticeList; |
||||
} |
||||
|
||||
public void setNoticeList(List<Notice> noticeList) { |
||||
this.noticeList = noticeList; |
||||
} |
||||
} |
||||
|
@ -1,9 +1,42 @@ |
||||
package com.community.pocket.ui.main.ui.forum.my; |
||||
|
||||
import androidx.annotation.StringRes; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.data.model.Forum; |
||||
import com.community.pocket.ui.main.ui.share.Response; |
||||
import com.community.pocket.ui.main.ui.share.ToastResponse; |
||||
import com.community.pocket.util.CustomMessage; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ForumMyResponse extends Response<List<Forum>> { |
||||
public class ForumMyResponse extends ToastResponse<ForumMyResponse.Msg> { |
||||
private List<Forum> forumList; |
||||
|
||||
public List<Forum> getForumList() { |
||||
return forumList; |
||||
} |
||||
|
||||
public void setForumList(List<Forum> forumList) { |
||||
this.forumList = forumList; |
||||
} |
||||
|
||||
enum Msg implements CustomMessage { |
||||
ok(R.string.load_forum_my_ok), |
||||
fail(R.string.load_forum_my_fail), |
||||
token(R.string.invalid_token); |
||||
|
||||
private Integer msg; |
||||
|
||||
Msg(@StringRes Integer msg) { |
||||
this.msg = msg; |
||||
} |
||||
|
||||
@NotNull |
||||
@Override |
||||
public Integer getMsg() { |
||||
return msg; |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,13 +1,45 @@ |
||||
package com.community.pocket.ui.main.ui.forum.news; |
||||
|
||||
import androidx.annotation.StringRes; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.data.model.Forum; |
||||
import com.community.pocket.ui.main.ui.share.Response; |
||||
import com.community.pocket.ui.main.ui.share.ToastResponse; |
||||
import com.community.pocket.util.CustomMessage; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 最新帖子响应实体 |
||||
*/ |
||||
public class ForumNewResponse extends Response<List<Forum>> { |
||||
public class ForumNewResponse extends ToastResponse<ForumNewResponse.Msg> { |
||||
private List<Forum> forumList; |
||||
|
||||
enum Msg implements CustomMessage { |
||||
ok(R.string.load_forum_new_ok), |
||||
fail(R.string.load_forum_new_fail); |
||||
|
||||
|
||||
private Integer msg; |
||||
|
||||
Msg(@StringRes Integer msg) { |
||||
this.msg = msg; |
||||
} |
||||
|
||||
@NotNull |
||||
@Override |
||||
public Integer getMsg() { |
||||
return msg; |
||||
} |
||||
} |
||||
|
||||
public List<Forum> getForumList() { |
||||
return forumList; |
||||
} |
||||
|
||||
public void setForumList(List<Forum> forumList) { |
||||
this.forumList = forumList; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,62 @@ |
||||
package com.community.pocket.util; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import androidx.lifecycle.LiveData; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
import androidx.room.Database; |
||||
import androidx.room.Room; |
||||
import androidx.room.RoomDatabase; |
||||
|
||||
import com.community.pocket.data.dao.TokenDao; |
||||
import com.community.pocket.data.model.Token; |
||||
|
||||
@Database(entities = {Token.class}, version = 1, exportSchema = false) |
||||
public abstract class AppDatabase extends RoomDatabase { |
||||
public abstract TokenDao tokenDao(); |
||||
|
||||
private static AppDatabase sInstance; |
||||
|
||||
public static final String DATABASE_NAME = "basic-sample-db"; |
||||
|
||||
private final MutableLiveData<Boolean> mIsDatabaseCreated = new MutableLiveData<>(); |
||||
|
||||
public static AppDatabase getInstance(Context context) { |
||||
if (sInstance == null) { |
||||
synchronized (AppDatabase.class) { |
||||
if (sInstance == null) { |
||||
sInstance = buildDatabase(context.getApplicationContext()); |
||||
sInstance.updateDatabaseCreated(context.getApplicationContext()); |
||||
} |
||||
} |
||||
} |
||||
return sInstance; |
||||
} |
||||
|
||||
/** |
||||
* Build the database. {@link Builder#build()} only sets up the database configuration and |
||||
* creates a new instance of the database. |
||||
* The SQLite database is only created when it's accessed for the first time. |
||||
*/ |
||||
private static AppDatabase buildDatabase(Context appContext) { |
||||
return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME) |
||||
.build(); |
||||
} |
||||
|
||||
/** |
||||
* Check whether the database already exists and expose it via {@link #getDatabaseCreated()} |
||||
*/ |
||||
private void updateDatabaseCreated(final Context context) { |
||||
if (context.getDatabasePath(DATABASE_NAME).exists()) { |
||||
setDatabaseCreated(); |
||||
} |
||||
} |
||||
|
||||
private void setDatabaseCreated() { |
||||
mIsDatabaseCreated.postValue(true); |
||||
} |
||||
|
||||
public LiveData<Boolean> getDatabaseCreated() { |
||||
return mIsDatabaseCreated; |
||||
} |
||||
} |
Loading…
Reference in new issue