Open "My location" tab and dismiss all dialogs after click on notification
This commit is contained in:
parent
aecf98195c
commit
99f8e828dc
3 changed files with 24 additions and 0 deletions
|
@ -7,6 +7,7 @@ import android.support.v4.app.NotificationCompat
|
|||
import android.support.v4.app.NotificationManagerCompat
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.ui.MainActivity
|
||||
import net.osmand.telegram.ui.OPEN_MY_LOCATION_TAB_KEY
|
||||
|
||||
|
||||
abstract class TelegramNotification(protected var app: TelegramApplication, val groupName: String) {
|
||||
|
@ -45,6 +46,7 @@ abstract class TelegramNotification(protected var app: TelegramApplication, val
|
|||
@SuppressLint("InlinedApi")
|
||||
protected fun createBuilder(wearable: Boolean): NotificationCompat.Builder {
|
||||
val contentIntent = Intent(app, MainActivity::class.java)
|
||||
contentIntent.putExtra(OPEN_MY_LOCATION_TAB_KEY, true)
|
||||
val contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
|
@ -30,6 +31,8 @@ import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_EXT
|
|||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
const val OPEN_MY_LOCATION_TAB_KEY = "open_my_location_tab"
|
||||
|
||||
private const val PERMISSION_REQUEST_LOCATION = 1
|
||||
|
||||
private const val MY_LOCATION_TAB_POS = 0
|
||||
|
@ -188,6 +191,14 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
if (intent.getBooleanExtra(OPEN_MY_LOCATION_TAB_KEY, false)) {
|
||||
AndroidUtils.dismissAllDialogs(supportFragmentManager)
|
||||
bottomNav.selectedItemId = R.id.action_my_location
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTelegramStatusChanged(prevTelegramAuthorizationState: TelegramAuthorizationState,
|
||||
newTelegramAuthorizationState: TelegramAuthorizationState) {
|
||||
runOnUi {
|
||||
|
|
|
@ -14,6 +14,8 @@ import android.os.Build
|
|||
import android.support.annotation.AttrRes
|
||||
import android.support.annotation.ColorInt
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.content.FileProvider
|
||||
import android.util.TypedValue
|
||||
import android.util.TypedValue.COMPLEX_UNIT_DIP
|
||||
|
@ -53,6 +55,15 @@ object AndroidUtils {
|
|||
}
|
||||
}
|
||||
|
||||
fun dismissAllDialogs(fm: FragmentManager) {
|
||||
for (fragment in fm.fragments) {
|
||||
if (fragment is DialogFragment) {
|
||||
fragment.dismissAllowingStateLoss()
|
||||
}
|
||||
dismissAllDialogs(fragment.childFragmentManager)
|
||||
}
|
||||
}
|
||||
|
||||
fun isLocationPermissionAvailable(context: Context): Boolean {
|
||||
return ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue