This commit is contained in:
Shabinder 2020-11-09 10:56:31 +05:30
parent c489c8c84a
commit ac423623e6
9 changed files with 34 additions and 37 deletions

View File

@ -123,7 +123,7 @@ dependencies {
implementation 'com.mpatric:mp3agic:0.9.1'
implementation 'com.shreyaspatil:EasyUpiPayment:3.0.0'
implementation 'com.github.sealedtx:java-youtube-downloader:2.4.3'
implementation 'com.github.sealedtx:java-youtube-downloader:2.4.4'
implementation "androidx.tonyodev.fetch2:xfetch2:3.1.5"
implementation 'com.github.javiersantos:AppUpdater:2.7'

View File

@ -21,7 +21,6 @@ import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Build
import android.os.Bundle
@ -33,13 +32,14 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.findNavController
import com.github.javiersantos.appupdater.AppUpdater
import com.github.javiersantos.appupdater.enums.UpdateFrom
import com.shabinder.spotiflyer.databinding.MainActivityBinding
import com.shabinder.spotiflyer.networking.SpotifyService
import com.shabinder.spotiflyer.networking.SpotifyServiceTokenRequest
import com.shabinder.spotiflyer.utils.NetworkInterceptor
import com.shabinder.spotiflyer.utils.Provider.activity
import com.shabinder.spotiflyer.utils.createDirectories
import com.shabinder.spotiflyer.utils.isOnline
import com.shabinder.spotiflyer.utils.startService
@ -53,25 +53,28 @@ import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Inject
/*
* This is App's God Activity
* */
@Suppress("DEPRECATION")
@AndroidEntryPoint
class MainActivity : AppCompatActivity(){
private var spotifyService : SpotifyService? = null
private var sharedPref :SharedPreferences? = null
private lateinit var binding: MainActivityBinding
lateinit var snackBarAnchor: View
private lateinit var sharedViewModel: SharedViewModel
private lateinit var navController: NavController
@Inject lateinit var moshi: Moshi
@Inject lateinit var spotifyServiceTokenRequest: SpotifyServiceTokenRequest
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.main_activity)
snackBarAnchor = binding.snackBarPosition
sharedViewModel = ViewModelProvider(this).get(SharedViewModel::class.java)
navController = findNavController(R.id.navHostFragment)
snackBarAnchor = binding.snackBarPosition
//Enabling Dark Mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
sharedPref = this.getPreferences(Context.MODE_PRIVATE)
authenticateSpotify()
@ -89,7 +92,8 @@ class MainActivity : AppCompatActivity(){
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.i("NEW INTENT", "Received")
//Return to MainFragment For Further Processing of this Intent
navController.popBackStack(R.id.mainFragment,false)
handleIntentFromExternalActivity(intent)
}
@ -100,9 +104,10 @@ class MainActivity : AppCompatActivity(){
this.getSystemService(Context.POWER_SERVICE) as PowerManager
val isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(packageName)
if (!isIgnoringBatteryOptimizations) {
val intent = Intent()
intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
intent.data = Uri.parse("package:$packageName")
val intent = Intent().apply{
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = Uri.parse("package:$packageName")
}
startActivityForResult(intent, 1233)
}
}
@ -188,6 +193,8 @@ class MainActivity : AppCompatActivity(){
.setUpdateFrom(UpdateFrom.XML)
.setUpdateXML("https://raw.githubusercontent.com/Shabinder/SpotiFlyer/master/app/src/main/res/xml/app_update.xml")
.setCancelable(false)
.setButtonDoNotShowAgain("Remind Later")
.setButtonDoNotShowAgainClickListener { dialog, _ -> dialog.dismiss() }
.setButtonUpdateClickListener { _, _ ->
val uri: Uri =
Uri.parse("http://github.com/Shabinder/SpotiFlyer/releases")
@ -200,7 +207,12 @@ class MainActivity : AppCompatActivity(){
appUpdater.start()
}
companion object{
private lateinit var instance: MainActivity
fun getInstance():MainActivity = instance
}
init {
activity = this
instance = this
}
}

View File

@ -107,6 +107,9 @@ class MainFragment : Fragment() {
sharedViewModel.intentString.observe(viewLifecycleOwner,{
if(it != ""){
sharedViewModel.uiScope.launch(Dispatchers.IO) {
//Wait for any Authentication to Finish ,
// this Wait prevents from multiple Authentication Requests
Thread.sleep(1000)
if(sharedViewModel.spotifyService.value == null){
//Not Authenticated Yet
Provider.activity.authenticateSpotify()

View File

@ -173,16 +173,6 @@ class SpotifyFragment : Fragment() {
*Live Data Observers
**/
private fun initializeLiveDataObservers() {
/**
* CoverUrl Binding Observer!
**/
viewModel.coverUrl.observe(viewLifecycleOwner, {
if(it!="Loading") bindImage(binding.coverImage,it, Source.Spotify)
})
/**
* TrackList Binding Observer!
**/
viewModel.trackList.observe(viewLifecycleOwner, {
if (it.isNotEmpty()){
Log.i("SpotifyFragment","TrackList Updated")
@ -191,19 +181,12 @@ class SpotifyFragment : Fragment() {
}
})
/**
* Title Binding Observer!
**/
viewModel.title.observe(viewLifecycleOwner, {
binding.titleView.text = it
viewModel.coverUrl.observe(viewLifecycleOwner, {
if(it!="Loading") bindImage(binding.coverImage,it, Source.Spotify)
})
sharedViewModel.intentString.observe(viewLifecycleOwner,{
//Waiting for Authentication to Finish with Spotify()Access Token Observe
if(it != "" && it!=SpotifyFragmentArgs.fromBundle(requireArguments()).link){
//New Intent Received , Time TO RELOAD
(activity as MainActivity).onBackPressed()
}
viewModel.title.observe(viewLifecycleOwner, {
binding.titleView.text = it
})
}
@ -215,7 +198,6 @@ class SpotifyFragment : Fragment() {
setImageResource(R.drawable.ic_tick)
visibility = View.VISIBLE
clearAnimation()
keepScreenOn = false
}
}
}

View File

@ -181,7 +181,6 @@ class YoutubeFragment : Fragment() {
setImageResource(R.drawable.ic_tick)
visibility = View.VISIBLE
clearAnimation()
keepScreenOn = false
}
}
}

View File

@ -49,7 +49,7 @@ import javax.inject.Singleton
@Module
object Provider {
lateinit var activity: MainActivity
val activity: MainActivity = MainActivity.getInstance()
val defaultDir = Environment.DIRECTORY_MUSIC + File.separator + "SpotiFlyer" + File.separator

View File

@ -20,6 +20,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="@color/black"
android:layout_height="match_parent">
<TextView
@ -43,6 +44,7 @@
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"

View File

@ -38,7 +38,7 @@
app:layout_constraintStart_toStartOf="parent" />
<fragment
android:id="@+id/NavHostFragment"
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"

View File

@ -46,7 +46,6 @@
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/downloading_fab"
android:layout_width="wrap_content"
android:keepScreenOn="true"
android:layout_height="wrap_content"
android:backgroundTint="@color/black"
android:scaleType="fitCenter"