Skip to content

Commit

Permalink
unify error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kidozh committed Mar 24, 2021
1 parent bdb1b4d commit 60a80e8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ThreadActivity : BaseStatusActivity(), OnSmileyPressedInteraction, onFilte
var authorid = 0
val threadResult = threadDetailViewModel.threadPostResultMutableLiveData.value
val viewThreadQueryStatus : ViewThreadQueryStatus = threadDetailViewModel.threadStatusMutableLiveData.value as ViewThreadQueryStatus
if (threadResult?.threadPostVariables != null && threadResult.threadPostVariables.detailedThreadInfo != null) {
if (threadResult?.threadPostVariables != null) {
authorid = threadResult.threadPostVariables.detailedThreadInfo.authorId
}
// update list
Expand Down Expand Up @@ -248,9 +248,7 @@ class ThreadActivity : BaseStatusActivity(), OnSmileyPressedInteraction, onFilte
Toasty.error(application,
getString(R.string.discuz_api_message_template, errorMessage.key, errorMessage.content),
Toast.LENGTH_LONG).show()
networkIndicatorAdapter.setErrorStatus(ErrorMessage(
errorMessage.key, errorMessage.content, R.drawable.ic_error_outline_24px
))
networkIndicatorAdapter.setErrorStatus(errorMessage)
VibrateUtils.vibrateForError(application)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ class ThreadPageActivity : BaseStatusActivity() , SmileyFragment.OnSmileyPressed
Toasty.error(application,
getString(R.string.discuz_api_message_template, errorMessage.key, errorMessage.content),
Toast.LENGTH_LONG).show()
networkIndicatorAdapter.setErrorStatus(ErrorMessage(
errorMessage.key, errorMessage.content, R.drawable.ic_error_outline_24px
))
networkIndicatorAdapter.setErrorStatus(errorMessage)
VibrateUtils.vibrateForError(application)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ public void onChanged(Boolean aBoolean) {
binding.errorView.setVisibility(View.VISIBLE);
binding.errorContent.setText(errorMessage.content);
binding.errorValue.setText(errorMessage.key);
binding.errorIcon.setImageResource(R.drawable.ic_error_outline_24px);
if(errorMessage.errorIconResource == 0){
binding.errorIcon.setImageResource(R.drawable.ic_error_outline_24px);
}
else{
binding.errorIcon.setImageResource(errorMessage.errorIconResource);
}

}
else {
binding.errorView.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ class HomeFragment : Fragment() {
homeViewModel.errorMessageMutableLiveData.observe(viewLifecycleOwner, { errorMessage: ErrorMessage? ->
if (errorMessage != null) {
activityBbsForumIndexBinding.errorView.visibility = View.VISIBLE
activityBbsForumIndexBinding.errorIcon.setImageResource(R.drawable.ic_error_outline_24px)
if(errorMessage.errorIconResource == 0){
activityBbsForumIndexBinding.errorIcon.setImageResource(R.drawable.ic_error_outline_24px)
}
else{
activityBbsForumIndexBinding.errorIcon.setImageResource(errorMessage.errorIconResource)
}

activityBbsForumIndexBinding.errorValue.text = errorMessage.key
activityBbsForumIndexBinding.errorContent.text = errorMessage.content
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static boolean isOnline(Context context) {

public static ErrorMessage getOfflineErrorMessage(Context context){
return new ErrorMessage(context.getString(R.string.network_state_unavaliable_error_key),
context.getString(R.string.network_state_unavaliable_error_content));
context.getString(R.string.network_state_unavaliable_error_content),R.drawable.ic_baseline_signal_cellular_connected_no_internet_4_bar_24);
}

public static boolean isWifiConnected(@NonNull Context context){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ForumViewModel(application: Application) : AndroidViewModel(application) {
var networkState = MutableLiveData(ConstUtils.NETWORK_STATUS_SUCCESSFULLY)
@JvmField
val totalThreadListMutableLiveData: MutableLiveData<List<Thread>> = MutableLiveData<List<Thread>>(ArrayList())
private var newThreadListMutableLiveData: MutableLiveData<List<Thread>?>? = null
private var newThreadListMutableLiveData: MutableLiveData<List<Thread>> = MutableLiveData(ArrayList())
var draftNumberLiveData: LiveData<Int>
@JvmField
var forumDetailedInfoMutableLiveData: MutableLiveData<Forum>
Expand All @@ -49,14 +49,7 @@ class ForumViewModel(application: Application) : AndroidViewModel(application) {
var errorMessageMutableLiveData = MutableLiveData<ErrorMessage?>(null)
@JvmField
var loadAllNoticeOnce = MutableLiveData(false)
fun getNewThreadListMutableLiveData(): MutableLiveData<List<Thread>?> {
if (newThreadListMutableLiveData == null) {
newThreadListMutableLiveData = MutableLiveData(ArrayList())
val displayForumQueryStatus = DisplayForumQueryStatus(forum.fid, 1)
setForumStatusAndFetchThread(displayForumQueryStatus)
}
return newThreadListMutableLiveData!!
}


fun setBBSInfo(discuz: Discuz, user: User?, forum: Forum) {
this.discuz = discuz
Expand Down Expand Up @@ -150,6 +143,7 @@ class ForumViewModel(application: Application) : AndroidViewModel(application) {
// check with api message
if (forumResult.message != null) {
errorMessageMutableLiveData.postValue(forumResult.message!!.toErrorMessage())
networkState.postValue(ConstUtils.NETWORK_STATUS_FAILED)
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="@color/colorWarn" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,18h2v-8h-2v8zM20,22h2v-2h-2v2zM2,22h16L18,8h4L22,2L2,22z"/>
</vector>

0 comments on commit 60a80e8

Please sign in to comment.