mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Check for authenticated user before a subscription sync.
This commit is contained in:
parent
7f5c44ca26
commit
790223e1ff
3 changed files with 17 additions and 2 deletions
|
@ -46,8 +46,7 @@ class InitActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun preferenceCheck() {
|
||||
val preferences = getSharedPreferences(PrefConstants.PREFERENCES, MODE_PRIVATE)
|
||||
if (preferences.getString(PrefConstants.PREF_COOKIE, null) != null) {
|
||||
if (PrefsUtils.hasCookie(this)) {
|
||||
val mainIntent = Intent(this, Main::class.java)
|
||||
startActivity(mainIntent)
|
||||
} else {
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.newsblur.subscription.SubscriptionManagerImpl
|
|||
import com.newsblur.util.AppConstants
|
||||
import com.newsblur.util.Log
|
||||
import com.newsblur.util.NBScope
|
||||
import com.newsblur.util.PrefsUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
@ -24,6 +25,11 @@ class SubscriptionSyncService : JobService() {
|
|||
|
||||
override fun onStartJob(params: JobParameters?): Boolean {
|
||||
Log.d(this, "onStartJob")
|
||||
if (!PrefsUtils.hasCookie(this)) {
|
||||
// no user authenticated
|
||||
return false
|
||||
}
|
||||
|
||||
NBScope.launch(Dispatchers.Default) {
|
||||
val subscriptionManager = SubscriptionManagerImpl(this@SubscriptionSyncService, this)
|
||||
val job = subscriptionManager.syncActiveSubscription()
|
||||
|
|
|
@ -1026,4 +1026,14 @@ public class PrefsUtils {
|
|||
editor.putBoolean(PrefConstants.IN_APP_REVIEW, true);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for logged in user.
|
||||
* @return whether a cookie is stored on disk
|
||||
* which gets saved when a user is authenticated.
|
||||
*/
|
||||
public static boolean hasCookie(Context context) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, Context.MODE_PRIVATE);
|
||||
return preferences.getString(PrefConstants.PREF_COOKIE, null) != null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue