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() {
|
private fun preferenceCheck() {
|
||||||
val preferences = getSharedPreferences(PrefConstants.PREFERENCES, MODE_PRIVATE)
|
if (PrefsUtils.hasCookie(this)) {
|
||||||
if (preferences.getString(PrefConstants.PREF_COOKIE, null) != null) {
|
|
||||||
val mainIntent = Intent(this, Main::class.java)
|
val mainIntent = Intent(this, Main::class.java)
|
||||||
startActivity(mainIntent)
|
startActivity(mainIntent)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.newsblur.subscription.SubscriptionManagerImpl
|
||||||
import com.newsblur.util.AppConstants
|
import com.newsblur.util.AppConstants
|
||||||
import com.newsblur.util.Log
|
import com.newsblur.util.Log
|
||||||
import com.newsblur.util.NBScope
|
import com.newsblur.util.NBScope
|
||||||
|
import com.newsblur.util.PrefsUtils
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@ -24,6 +25,11 @@ class SubscriptionSyncService : JobService() {
|
||||||
|
|
||||||
override fun onStartJob(params: JobParameters?): Boolean {
|
override fun onStartJob(params: JobParameters?): Boolean {
|
||||||
Log.d(this, "onStartJob")
|
Log.d(this, "onStartJob")
|
||||||
|
if (!PrefsUtils.hasCookie(this)) {
|
||||||
|
// no user authenticated
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
NBScope.launch(Dispatchers.Default) {
|
NBScope.launch(Dispatchers.Default) {
|
||||||
val subscriptionManager = SubscriptionManagerImpl(this@SubscriptionSyncService, this)
|
val subscriptionManager = SubscriptionManagerImpl(this@SubscriptionSyncService, this)
|
||||||
val job = subscriptionManager.syncActiveSubscription()
|
val job = subscriptionManager.syncActiveSubscription()
|
||||||
|
|
|
@ -1026,4 +1026,14 @@ public class PrefsUtils {
|
||||||
editor.putBoolean(PrefConstants.IN_APP_REVIEW, true);
|
editor.putBoolean(PrefConstants.IN_APP_REVIEW, true);
|
||||||
editor.commit();
|
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