Improve offline notice

This commit is contained in:
Phillip Thelen 2019-05-31 11:07:36 +02:00
parent 6c8f909a47
commit d2044f307c
8 changed files with 41 additions and 33 deletions

View file

@ -103,6 +103,17 @@
app:tabGravity="fill" app:tabGravity="fill"
app:tabIndicatorColor="?colorContentBackground" app:tabIndicatorColor="?colorContentBackground"
app:tabMode="fixed" /> app:tabMode="fixed" />
<TextView
android:id="@+id/connection_issue_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:background="@color/gray_50"
android:textSize="14sp"
android:gravity="center_horizontal"
android:padding="@dimen/spacing_small"
android:text="@string/internal_error_api"
android:visibility="gone"/>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<LinearLayout <LinearLayout

View file

@ -81,9 +81,8 @@
<!-- Network Errors --> <!-- Network Errors -->
<string name="network_error_title">Connection Error</string>
<string name="network_error_no_network_body">You are not connected to the internet.</string> <string name="network_error_no_network_body">You are not connected to the internet.</string>
<string name="internal_error_api">There seems to be a problem with the server. Try again later.</string> <string name="internal_error_api">Server connection lost</string>
<string name="authentication_error_title">Authentication Error</string> <string name="authentication_error_title">Authentication Error</string>
<string name="authentication_error_body">Your Username and/or Password was incorrect.</string> <string name="authentication_error_body">Your Username and/or Password was incorrect.</string>

View file

@ -260,19 +260,16 @@ class ApiClientImpl//private OnHabitsAPIResult mResultListener;
} }
private fun showConnectionProblemDialog(resourceMessageString: Int) { private fun showConnectionProblemDialog(resourceMessageString: Int) {
showConnectionProblemDialog(R.string.network_error_title, resourceMessageString) showConnectionProblemDialog(null, context.getString(resourceMessageString))
} }
private fun showConnectionProblemDialog(resourceTitleString: Int, resourceMessageString: Int) { private fun showConnectionProblemDialog(resourceTitleString: Int, resourceMessageString: Int) {
showConnectionProblemDialog(context.getString(resourceTitleString), context.getString(resourceMessageString)) showConnectionProblemDialog(context.getString(resourceTitleString), context.getString(resourceMessageString))
} }
private fun showConnectionProblemDialog(resourceTitleString: String, resourceMessageString: String) { private fun showConnectionProblemDialog(resourceTitleString: String?, resourceMessageString: String) {
val event = ShowConnectionProblemEvent(resourceTitleString, resourceMessageString) val event = ShowConnectionProblemEvent(resourceTitleString, resourceMessageString)
EventBus.getDefault().post(event) EventBus.getDefault().post(event)
if (BuildConfig.DEBUG) {
Log.d(TAG, "showConnectionProblemDialog: $resourceTitleString $resourceMessageString")
}
} }
/* /*

View file

@ -1,16 +0,0 @@
package com.habitrpg.android.habitica.events;
/**
* Created by phillip on 25.07.17.
*/
public class ShowConnectionProblemEvent {
public String title;
public String message;
public ShowConnectionProblemEvent(String title, String message) {
this.title = title;
this.message = message;
}
}

View file

@ -0,0 +1,7 @@
package com.habitrpg.android.habitica.events
/**
* Created by phillip on 25.07.17.
*/
class ShowConnectionProblemEvent(var title: String?, var message: String)

View file

@ -100,7 +100,7 @@ abstract class BaseActivity : AppCompatActivity() {
} }
@Subscribe @Subscribe
fun onEvent(event: ShowConnectionProblemEvent) { open fun onEvent(event: ShowConnectionProblemEvent) {
val alert = HabiticaAlertDialog(this) val alert = HabiticaAlertDialog(this)
alert.setTitle(event.title) alert.setTitle(event.title)
alert.setMessage(event.message) alert.setMessage(event.message)

View file

@ -12,6 +12,7 @@ import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.BitmapDrawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.util.Log import android.util.Log
import android.util.TypedValue import android.util.TypedValue
@ -137,6 +138,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
internal val detailTabs: TabLayout? by bindOptionalView(R.id.detail_tabs) internal val detailTabs: TabLayout? by bindOptionalView(R.id.detail_tabs)
val avatarWithBars: View by bindView(R.id.avatar_with_bars) val avatarWithBars: View by bindView(R.id.avatar_with_bars)
private val overlayLayout: ViewGroup by bindView(R.id.overlayFrameLayout) private val overlayLayout: ViewGroup by bindView(R.id.overlayFrameLayout)
private val connectionIssueTextView: TextView by bindView(R.id.connection_issue_textview)
var user: User? = null var user: User? = null
@ -148,6 +150,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
private var drawerToggle: ActionBarDrawerToggle? = null private var drawerToggle: ActionBarDrawerToggle? = null
private var keyboardUtil: KeyboardUtil? = null private var keyboardUtil: KeyboardUtil? = null
private var resumeFromActivity = false private var resumeFromActivity = false
private var connectionIssueHandler: Handler? = null
private val statusBarHeight: Int private val statusBarHeight: Int
get() { get() {
@ -834,6 +837,20 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
}, RxErrorHandler.handleEmptyError()) }, RxErrorHandler.handleEmptyError())
} }
override fun onEvent(event: ShowConnectionProblemEvent) {
if (event.title != null) {
super.onEvent(event)
} else {
connectionIssueHandler?.removeCallbacksAndMessages(null)
connectionIssueTextView.visibility = View.VISIBLE
connectionIssueTextView.text = event.message
connectionIssueHandler = Handler()
connectionIssueHandler?.postDelayed({
connectionIssueTextView.visibility = View.GONE
}, 5000)
}
}
companion object { companion object {
const val SELECT_CLASS_RESULT = 11 const val SELECT_CLASS_RESULT = 11

View file

@ -1,14 +1,11 @@
package com.habitrpg.android.habitica.widget package com.habitrpg.android.habitica.widget
import android.annotation.TargetApi
import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider import android.appwidget.AppWidgetProvider
import android.content.Context import android.content.Context
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.widget.RemoteViews import android.widget.RemoteViews
import android.widget.Toast import android.widget.Toast
import com.habitrpg.android.habitica.HabiticaBaseApplication
import com.habitrpg.android.habitica.data.UserRepository import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.helpers.AmplitudeManager import com.habitrpg.android.habitica.helpers.AmplitudeManager
import com.habitrpg.android.habitica.interactors.NotifyUserUseCase import com.habitrpg.android.habitica.interactors.NotifyUserUseCase
@ -20,7 +17,7 @@ import javax.inject.Inject
abstract class BaseWidgetProvider : AppWidgetProvider() { abstract class BaseWidgetProvider : AppWidgetProvider() {
@Inject @Inject
var userRepository: UserRepository? = null lateinit var userRepository: UserRepository
protected var context: Context? = null protected var context: Context? = null
@ -60,16 +57,12 @@ abstract class BaseWidgetProvider : AppWidgetProvider() {
// First find out rows and columns based on width provided. // First find out rows and columns based on width provided.
val rows = getCellsForSize(minHeight) val rows = getCellsForSize(minHeight)
val columns = getCellsForSize(minWidth) val columns = getCellsForSize(minWidth)
val remoteViews = RemoteViews(context.packageName, val remoteViews = RemoteViews(context?.packageName, layoutResourceId())
layoutResourceId())
return configureRemoteViews(remoteViews, widgetId, columns, rows) return configureRemoteViews(remoteViews, widgetId, columns, rows)
} }
protected fun showToastForTaskDirection(context: Context, data: TaskScoringResult?, userID: String) { protected fun showToastForTaskDirection(context: Context, data: TaskScoringResult?, userID: String) {
if (userRepository == null) {
HabiticaBaseApplication.component?.inject(this)
}
if (data != null) { if (data != null) {
val pair = NotifyUserUseCase.getNotificationAndAddStatsToUserAsText(context, data.experienceDelta!!, data.healthDelta!!, data.goldDelta!!, data.manaDelta!!) val pair = NotifyUserUseCase.getNotificationAndAddStatsToUserAsText(context, data.experienceDelta!!, data.healthDelta!!, data.goldDelta!!, data.manaDelta!!)
val toast = Toast.makeText(context, pair.first, Toast.LENGTH_LONG) val toast = Toast.makeText(context, pair.first, Toast.LENGTH_LONG)