mirror of https://github.com/readrops/Readrops.git
Add notifications permission list
This commit is contained in:
parent
513b455255
commit
4987a70efa
|
@ -38,6 +38,9 @@ android {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = '1.8'
|
||||||
|
}
|
||||||
dataBinding {
|
dataBinding {
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
|
@ -59,6 +62,8 @@ dependencies {
|
||||||
implementation "androidx.core:core-ktx:1.2.0"
|
implementation "androidx.core:core-ktx:1.2.0"
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation "androidx.work:work-runtime-ktx:2.3.2"
|
implementation "androidx.work:work-runtime-ktx:2.3.2"
|
||||||
|
implementation "androidx.fragment:fragment-ktx:1.2.2"
|
||||||
|
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
|
@ -75,6 +80,7 @@ dependencies {
|
||||||
|
|
||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
kapt 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
|
kapt 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
|
||||||
|
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
|
||||||
|
|
||||||
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
|
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,16 @@ package com.readrops.app.activities
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.activity.viewModels
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.readrops.app.R
|
import com.readrops.app.R
|
||||||
import com.readrops.app.adapters.NotificationPermissionAdapter
|
import com.readrops.app.adapters.NotificationPermissionAdapter
|
||||||
import com.readrops.app.databinding.ActivityNotificationPermissionBinding
|
import com.readrops.app.databinding.ActivityNotificationPermissionBinding
|
||||||
|
import com.readrops.app.utils.ReadropsKeys.ACCOUNT
|
||||||
|
import com.readrops.app.viewmodels.NotificationPermissionViewModel
|
||||||
|
|
||||||
class NotificationPermissionActivity : AppCompatActivity() {
|
class NotificationPermissionActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
@ -16,6 +21,29 @@ class NotificationPermissionActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_notification_permission)
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_notification_permission)
|
||||||
|
|
||||||
|
setTitle(R.string.notifications)
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
|
val viewModel by viewModels<NotificationPermissionViewModel>()
|
||||||
|
viewModel.account = intent.getParcelableExtra(ACCOUNT)
|
||||||
|
|
||||||
|
val adapter = NotificationPermissionAdapter {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
binding.notifPermissionAccountList.layoutManager = LinearLayoutManager(this)
|
binding.notifPermissionAccountList.layoutManager = LinearLayoutManager(this)
|
||||||
|
binding.notifPermissionAccountList.adapter = adapter
|
||||||
|
|
||||||
|
viewModel.getFeedsWithNotifPermission().observe(this, Observer {
|
||||||
|
adapter.submitList(it)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
android.R.id.home -> finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.readrops.app.adapters
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.readrops.app.R
|
||||||
|
import com.readrops.app.databinding.NotificationLayoutBinding
|
||||||
|
import com.readrops.readropsdb.entities.Feed
|
||||||
|
|
||||||
|
class NotificationPermissionAdapter(val listener: (feed: Feed) -> Unit) : ListAdapter<Feed, NotificationPermissionAdapter.NotificationPermissionViewHolder>(DIFF_CALLBACK) {
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationPermissionViewHolder {
|
||||||
|
val binding = DataBindingUtil.inflate<NotificationLayoutBinding>(LayoutInflater.from(parent.context), R.layout.notification_layout, parent, false)
|
||||||
|
|
||||||
|
return NotificationPermissionViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: NotificationPermissionViewHolder, position: Int) {
|
||||||
|
val feed = getItem(position)
|
||||||
|
|
||||||
|
holder.binding.notificationFeedName.text = feed.name
|
||||||
|
holder.binding.notificationSwitch.isChecked = feed.isNotificationEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: NotificationPermissionViewHolder, position: Int, payloads: MutableList<Any>) {
|
||||||
|
if (payloads.isNotEmpty()) {
|
||||||
|
val feed = payloads.first() as Feed
|
||||||
|
holder.binding.notificationSwitch.isChecked = feed.isNotificationEnabled
|
||||||
|
} else onBindViewHolder(holder, position)
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class NotificationPermissionViewHolder(val binding: NotificationLayoutBinding) : RecyclerView.ViewHolder(binding.root)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Feed>() {
|
||||||
|
override fun areItemsTheSame(oldItem: Feed, newItem: Feed): Boolean {
|
||||||
|
return oldItem.id == newItem.id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: Feed, newItem: Feed): Boolean {
|
||||||
|
return oldItem.isNotificationEnabled == newItem.isNotificationEnabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import com.readrops.app.R;
|
||||||
import com.readrops.app.ReadropsApp;
|
import com.readrops.app.ReadropsApp;
|
||||||
import com.readrops.app.activities.AddAccountActivity;
|
import com.readrops.app.activities.AddAccountActivity;
|
||||||
import com.readrops.app.activities.ManageFeedsFoldersActivity;
|
import com.readrops.app.activities.ManageFeedsFoldersActivity;
|
||||||
|
import com.readrops.app.activities.NotificationPermissionActivity;
|
||||||
import com.readrops.app.utils.PermissionManager;
|
import com.readrops.app.utils.PermissionManager;
|
||||||
import com.readrops.app.utils.SharedPreferencesManager;
|
import com.readrops.app.utils.SharedPreferencesManager;
|
||||||
import com.readrops.app.utils.Utils;
|
import com.readrops.app.utils.Utils;
|
||||||
|
@ -86,6 +87,7 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
||||||
Preference credentialsPref = findPreference("credentials_key");
|
Preference credentialsPref = findPreference("credentials_key");
|
||||||
Preference deleteAccountPref = findPreference("delete_account_key");
|
Preference deleteAccountPref = findPreference("delete_account_key");
|
||||||
Preference opmlPref = findPreference("opml_import_export");
|
Preference opmlPref = findPreference("opml_import_export");
|
||||||
|
Preference notificationPref = findPreference("notifications");
|
||||||
|
|
||||||
if (account.is(AccountType.LOCAL))
|
if (account.is(AccountType.LOCAL))
|
||||||
credentialsPref.setVisible(false);
|
credentialsPref.setVisible(false);
|
||||||
|
@ -132,6 +134,14 @@ public class AccountSettingsFragment extends PreferenceFragmentCompat {
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
notificationPref.setOnPreferenceClickListener(preference -> {
|
||||||
|
Intent intent = new Intent(getContext(), NotificationPermissionActivity.class);
|
||||||
|
intent.putExtra(ACCOUNT, account);
|
||||||
|
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.readrops.app.viewmodels
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import com.readrops.readropsdb.Database
|
||||||
|
import com.readrops.readropsdb.entities.Feed
|
||||||
|
import com.readrops.readropsdb.entities.account.Account
|
||||||
|
|
||||||
|
class NotificationPermissionViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
|
||||||
|
val database = Database.getInstance(application)
|
||||||
|
var account: Account? = null
|
||||||
|
|
||||||
|
|
||||||
|
fun getFeedsWithNotifPermission(): LiveData<List<Feed>> = database.feedDao()
|
||||||
|
.getFeedsForNotifPermission(account?.id!!)
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<vector android:height="24dp" android:tint="#727272"
|
||||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
|
||||||
|
</vector>
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:layout_marginEnd="6dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/notification_feed_icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
tools:src="@drawable/ic_rss_feed_grey" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/notification_feed_name"
|
||||||
|
style="@style/TextAppearance.AppCompat.Subhead"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="6dp"
|
||||||
|
android:layout_toStartOf="@id/notification_switch"
|
||||||
|
android:layout_toEndOf="@id/notification_feed_icon"
|
||||||
|
tools:text="Feed 1" />
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/notification_switch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
</layout>
|
|
@ -124,5 +124,6 @@
|
||||||
<string name="account_synchro">Synchronisation des comptes</string>
|
<string name="account_synchro">Synchronisation des comptes</string>
|
||||||
<string name="new_items">%1$s nouveaux articles</string>
|
<string name="new_items">%1$s nouveaux articles</string>
|
||||||
<string name="enable_notifications">Activer les notifications</string>
|
<string name="enable_notifications">Activer les notifications</string>
|
||||||
|
<string name="notifications">Notifications</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -130,4 +130,5 @@
|
||||||
<string name="account_synchro">Accounts synchronisation</string>
|
<string name="account_synchro">Accounts synchronisation</string>
|
||||||
<string name="new_items">%1$s new articles</string>
|
<string name="new_items">%1$s new articles</string>
|
||||||
<string name="enable_notifications">Enable notifications</string>
|
<string name="enable_notifications">Enable notifications</string>
|
||||||
|
<string name="notifications">Notifications</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
android:key="feeds_folders_key"
|
android:key="feeds_folders_key"
|
||||||
android:title="@string/feeds_and_folders" />
|
android:title="@string/feeds_and_folders" />
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
android:icon="@drawable/ic_notifications"
|
||||||
|
android:key="notifications"
|
||||||
|
android:title="@string/notifications" />
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:icon="@drawable/ic_account"
|
android:icon="@drawable/ic_account"
|
||||||
android:key="credentials_key"
|
android:key="credentials_key"
|
||||||
|
|
Loading…
Reference in New Issue