mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 03:39:00 +00:00
Improve offline notice
This commit is contained in:
parent
6c8f909a47
commit
d2044f307c
8 changed files with 41 additions and 33 deletions
|
|
@ -103,6 +103,17 @@
|
|||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="?colorContentBackground"
|
||||
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>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
|
|
@ -81,9 +81,8 @@
|
|||
|
||||
|
||||
<!-- 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="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_body">Your Username and/or Password was incorrect.</string>
|
||||
|
|
|
|||
|
|
@ -260,19 +260,16 @@ class ApiClientImpl//private OnHabitsAPIResult mResultListener;
|
|||
}
|
||||
|
||||
private fun showConnectionProblemDialog(resourceMessageString: Int) {
|
||||
showConnectionProblemDialog(R.string.network_error_title, resourceMessageString)
|
||||
showConnectionProblemDialog(null, context.getString(resourceMessageString))
|
||||
}
|
||||
|
||||
private fun showConnectionProblemDialog(resourceTitleString: Int, resourceMessageString: Int) {
|
||||
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)
|
||||
EventBus.getDefault().post(event)
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "showConnectionProblemDialog: $resourceTitleString $resourceMessageString")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -100,7 +100,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
fun onEvent(event: ShowConnectionProblemEvent) {
|
||||
open fun onEvent(event: ShowConnectionProblemEvent) {
|
||||
val alert = HabiticaAlertDialog(this)
|
||||
alert.setTitle(event.title)
|
||||
alert.setMessage(event.message)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import android.graphics.Canvas
|
|||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
|
|
@ -137,6 +138,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
internal val detailTabs: TabLayout? by bindOptionalView(R.id.detail_tabs)
|
||||
val avatarWithBars: View by bindView(R.id.avatar_with_bars)
|
||||
private val overlayLayout: ViewGroup by bindView(R.id.overlayFrameLayout)
|
||||
private val connectionIssueTextView: TextView by bindView(R.id.connection_issue_textview)
|
||||
|
||||
var user: User? = null
|
||||
|
||||
|
|
@ -148,6 +150,7 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
private var drawerToggle: ActionBarDrawerToggle? = null
|
||||
private var keyboardUtil: KeyboardUtil? = null
|
||||
private var resumeFromActivity = false
|
||||
private var connectionIssueHandler: Handler? = null
|
||||
|
||||
private val statusBarHeight: Int
|
||||
get() {
|
||||
|
|
@ -834,6 +837,20 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
}, 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 {
|
||||
|
||||
const val SELECT_CLASS_RESULT = 11
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
package com.habitrpg.android.habitica.widget
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.Toast
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager
|
||||
import com.habitrpg.android.habitica.interactors.NotifyUserUseCase
|
||||
|
|
@ -20,7 +17,7 @@ import javax.inject.Inject
|
|||
abstract class BaseWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
@Inject
|
||||
var userRepository: UserRepository? = null
|
||||
lateinit var userRepository: UserRepository
|
||||
|
||||
protected var context: Context? = null
|
||||
|
||||
|
|
@ -60,16 +57,12 @@ abstract class BaseWidgetProvider : AppWidgetProvider() {
|
|||
// First find out rows and columns based on width provided.
|
||||
val rows = getCellsForSize(minHeight)
|
||||
val columns = getCellsForSize(minWidth)
|
||||
val remoteViews = RemoteViews(context.packageName,
|
||||
layoutResourceId())
|
||||
val remoteViews = RemoteViews(context?.packageName, layoutResourceId())
|
||||
|
||||
return configureRemoteViews(remoteViews, widgetId, columns, rows)
|
||||
}
|
||||
|
||||
protected fun showToastForTaskDirection(context: Context, data: TaskScoringResult?, userID: String) {
|
||||
if (userRepository == null) {
|
||||
HabiticaBaseApplication.component?.inject(this)
|
||||
}
|
||||
if (data != null) {
|
||||
val pair = NotifyUserUseCase.getNotificationAndAddStatsToUserAsText(context, data.experienceDelta!!, data.healthDelta!!, data.goldDelta!!, data.manaDelta!!)
|
||||
val toast = Toast.makeText(context, pair.first, Toast.LENGTH_LONG)
|
||||
|
|
|
|||
Loading…
Reference in a new issue