Code Cleanup
This commit is contained in:
parent
7b3b52e3b0
commit
a67985d040
22 changed files with 340 additions and 542 deletions
|
@ -9,6 +9,7 @@ import code.name.monkey.retromusic.cast.RetroWebServer
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import com.google.android.gms.cast.framework.CastContext
|
import com.google.android.gms.cast.framework.CastContext
|
||||||
import com.google.android.gms.cast.framework.CastSession
|
import com.google.android.gms.cast.framework.CastSession
|
||||||
|
import com.google.android.gms.cast.framework.SessionManager
|
||||||
import com.google.android.gms.common.ConnectionResult
|
import com.google.android.gms.common.ConnectionResult
|
||||||
import com.google.android.gms.common.GoogleApiAvailability
|
import com.google.android.gms.common.GoogleApiAvailability
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ import com.google.android.gms.common.GoogleApiAvailability
|
||||||
abstract class AbsCastActivity : AbsSlidingMusicPanelActivity() {
|
abstract class AbsCastActivity : AbsSlidingMusicPanelActivity() {
|
||||||
|
|
||||||
private var mCastSession: CastSession? = null
|
private var mCastSession: CastSession? = null
|
||||||
private lateinit var castContext: CastContext
|
private lateinit var sessionManager: SessionManager
|
||||||
private var webServer: RetroWebServer? = null
|
private var webServer: RetroWebServer? = null
|
||||||
private var playServicesAvailable: Boolean = false
|
private var playServicesAvailable: Boolean = false
|
||||||
|
|
||||||
|
@ -87,17 +88,17 @@ abstract class AbsCastActivity : AbsSlidingMusicPanelActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupCast() {
|
private fun setupCast() {
|
||||||
castContext = CastContext.getSharedInstance(this)
|
sessionManager = CastContext.getSharedInstance(applicationContext).sessionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
if (playServicesAvailable) {
|
if (playServicesAvailable) {
|
||||||
castContext.sessionManager.addSessionManagerListener(
|
sessionManager.addSessionManagerListener(
|
||||||
sessionManagerListener,
|
sessionManagerListener,
|
||||||
CastSession::class.java
|
CastSession::class.java
|
||||||
)
|
)
|
||||||
if (mCastSession == null) {
|
if (mCastSession == null) {
|
||||||
mCastSession = castContext.sessionManager.currentCastSession
|
mCastSession = sessionManager.currentCastSession
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
|
@ -14,11 +14,8 @@
|
||||||
*/
|
*/
|
||||||
package code.name.monkey.retromusic.activities.bugreport
|
package code.name.monkey.retromusic.activities.bugreport
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Dialog
|
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -28,8 +25,8 @@ import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.StringDef
|
import androidx.annotation.StringDef
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
|
@ -43,10 +40,12 @@ import code.name.monkey.retromusic.activities.bugreport.model.github.GithubLogin
|
||||||
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget
|
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget
|
||||||
import code.name.monkey.retromusic.databinding.ActivityBugReportBinding
|
import code.name.monkey.retromusic.databinding.ActivityBugReportBinding
|
||||||
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
|
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
|
||||||
import code.name.monkey.retromusic.misc.DialogAsyncTask
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.egit.github.core.Issue
|
import org.eclipse.egit.github.core.Issue
|
||||||
import org.eclipse.egit.github.core.client.GitHubClient
|
import org.eclipse.egit.github.core.client.GitHubClient
|
||||||
import org.eclipse.egit.github.core.client.RequestException
|
import org.eclipse.egit.github.core.client.RequestException
|
||||||
|
@ -226,9 +225,9 @@ open class BugReportActivity : AbsThemeActivity() {
|
||||||
onSaveExtraInfo()
|
onSaveExtraInfo()
|
||||||
|
|
||||||
val report = Report(bugTitle, bugDescription, deviceInfo, extraInfo)
|
val report = Report(bugTitle, bugDescription, deviceInfo, extraInfo)
|
||||||
val target = GithubTarget("RetroMusicPlayer", "RetroMusicPlayer")
|
val target = GithubTarget("prathameshmm02", "RetroMusicPlayer")
|
||||||
|
|
||||||
ReportIssueAsyncTask.report(this, report, target, login)
|
reportIssue(report, target, login)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onSaveExtraInfo() {}
|
private fun onSaveExtraInfo() {}
|
||||||
|
@ -240,92 +239,75 @@ open class BugReportActivity : AbsThemeActivity() {
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ReportIssueAsyncTask private constructor(
|
private fun reportIssue(
|
||||||
activity: Activity,
|
report: Report,
|
||||||
private val report: Report,
|
target: GithubTarget,
|
||||||
private val target: GithubTarget,
|
login: GithubLogin
|
||||||
private val login: GithubLogin
|
) {
|
||||||
) : DialogAsyncTask<Void, Void, String>(activity) {
|
val client: GitHubClient = if (login.shouldUseApiToken()) {
|
||||||
|
GitHubClient().setOAuth2Token(login.apiToken)
|
||||||
override fun createDialog(context: Context): Dialog {
|
} else {
|
||||||
return AlertDialog.Builder(context).show()
|
GitHubClient().setCredentials(login.username, login.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Result
|
val issue = Issue().setTitle(report.title).setBody(report.getDescription())
|
||||||
override fun doInBackground(vararg params: Void): String {
|
|
||||||
val client: GitHubClient = if (login.shouldUseApiToken()) {
|
|
||||||
GitHubClient().setOAuth2Token(login.apiToken)
|
|
||||||
} else {
|
|
||||||
GitHubClient().setCredentials(login.username, login.password)
|
|
||||||
}
|
|
||||||
|
|
||||||
val issue = Issue().setTitle(report.title).setBody(report.description)
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
try {
|
val result = try {
|
||||||
IssueService(client).createIssue(target.username, target.repository, issue)
|
IssueService(client).createIssue(target.username, target.repository, issue)
|
||||||
return RESULT_SUCCESS
|
RESULT_SUCCESS
|
||||||
} catch (e: RequestException) {
|
} catch (e: RequestException) {
|
||||||
return when (e.status) {
|
when (e.status) {
|
||||||
STATUS_BAD_CREDENTIALS -> {
|
STATUS_BAD_CREDENTIALS -> {
|
||||||
if (login.shouldUseApiToken()) RESULT_INVALID_TOKEN else RESULT_BAD_CREDENTIALS
|
if (login.shouldUseApiToken()) RESULT_INVALID_TOKEN else RESULT_BAD_CREDENTIALS
|
||||||
}
|
}
|
||||||
STATUS_ISSUES_NOT_ENABLED -> RESULT_ISSUES_NOT_ENABLED
|
STATUS_ISSUES_NOT_ENABLED -> RESULT_ISSUES_NOT_ENABLED
|
||||||
else -> {
|
else -> {
|
||||||
e.printStackTrace()
|
|
||||||
RESULT_UNKNOWN
|
RESULT_UNKNOWN
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
return RESULT_UNKNOWN
|
RESULT_UNKNOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
val activity = this@BugReportActivity
|
||||||
|
when (result) {
|
||||||
|
RESULT_SUCCESS -> MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.bug_report_success)
|
||||||
|
.setPositiveButton(android.R.string.ok) { _, _ -> tryToFinishActivity() }
|
||||||
|
.show()
|
||||||
|
RESULT_BAD_CREDENTIALS -> MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.bug_report_failed)
|
||||||
|
.setMessage(R.string.bug_report_failed_wrong_credentials)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show()
|
||||||
|
RESULT_INVALID_TOKEN -> MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.bug_report_failed)
|
||||||
|
.setMessage(R.string.bug_report_failed_invalid_token)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show()
|
||||||
|
RESULT_ISSUES_NOT_ENABLED -> MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.bug_report_failed)
|
||||||
|
.setMessage(R.string.bug_report_failed_issues_not_available)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show()
|
||||||
|
else -> MaterialAlertDialogBuilder(activity)
|
||||||
|
.setTitle(R.string.bug_report_failed)
|
||||||
|
.setMessage(R.string.bug_report_failed_unknown)
|
||||||
|
.setPositiveButton(android.R.string.ok) { _, _ -> tryToFinishActivity() }
|
||||||
|
.setNegativeButton(android.R.string.cancel) { _, _ -> tryToFinishActivity() }
|
||||||
|
.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPostExecute(@Result result: String) {
|
private fun tryToFinishActivity() {
|
||||||
super.onPostExecute(result)
|
if (!isFinishing) {
|
||||||
|
finish()
|
||||||
val context = context ?: return
|
|
||||||
|
|
||||||
when (result) {
|
|
||||||
RESULT_SUCCESS -> tryToFinishActivity()
|
|
||||||
RESULT_BAD_CREDENTIALS -> MaterialAlertDialogBuilder(context)
|
|
||||||
.setTitle(R.string.bug_report_failed)
|
|
||||||
.setMessage(R.string.bug_report_failed_wrong_credentials)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.show()
|
|
||||||
RESULT_INVALID_TOKEN -> MaterialAlertDialogBuilder(context)
|
|
||||||
.setTitle(R.string.bug_report_failed)
|
|
||||||
.setMessage(R.string.bug_report_failed_invalid_token)
|
|
||||||
.setPositiveButton(android.R.string.ok, null).show()
|
|
||||||
RESULT_ISSUES_NOT_ENABLED -> MaterialAlertDialogBuilder(context)
|
|
||||||
.setTitle(R.string.bug_report_failed)
|
|
||||||
.setMessage(R.string.bug_report_failed_issues_not_available)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
|
|
||||||
else -> MaterialAlertDialogBuilder(context)
|
|
||||||
.setTitle(R.string.bug_report_failed)
|
|
||||||
.setMessage(R.string.bug_report_failed_unknown)
|
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ -> tryToFinishActivity() }
|
|
||||||
.setNegativeButton(android.R.string.cancel) { _, _ -> tryToFinishActivity() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun tryToFinishActivity() {
|
|
||||||
val context = context
|
|
||||||
if (context is Activity && !context.isFinishing) {
|
|
||||||
context.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun report(
|
|
||||||
activity: Activity,
|
|
||||||
report: Report,
|
|
||||||
target: GithubTarget,
|
|
||||||
login: GithubLogin
|
|
||||||
) {
|
|
||||||
ReportIssueAsyncTask(activity, report, target, login).execute()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,6 +315,6 @@ open class BugReportActivity : AbsThemeActivity() {
|
||||||
|
|
||||||
private const val STATUS_BAD_CREDENTIALS = 401
|
private const val STATUS_BAD_CREDENTIALS = 401
|
||||||
private const val STATUS_ISSUES_NOT_ENABLED = 410
|
private const val STATUS_ISSUES_NOT_ENABLED = 410
|
||||||
private const val ISSUE_TRACKER_LINK = "https://github.com/RetroMusicPlayer/RetroMusicPlayer"
|
private const val ISSUE_TRACKER_LINK = "https://github.com/prathameshmm02/RetroMusicPlayer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,202 +0,0 @@
|
||||||
package code.name.monkey.retromusic.activities.bugreport.model;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import androidx.annotation.IntRange;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
|
||||||
|
|
||||||
public class DeviceInfo {
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private final String[] abis =
|
|
||||||
Build.SUPPORTED_ABIS;
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private final String[] abis32Bits =
|
|
||||||
Build.SUPPORTED_32_BIT_ABIS;
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private final String[] abis64Bits =
|
|
||||||
Build.SUPPORTED_64_BIT_ABIS;
|
|
||||||
|
|
||||||
private final String baseTheme;
|
|
||||||
|
|
||||||
private final String brand = Build.BRAND;
|
|
||||||
|
|
||||||
private final String buildID = Build.DISPLAY;
|
|
||||||
|
|
||||||
private final String buildVersion = Build.VERSION.INCREMENTAL;
|
|
||||||
|
|
||||||
private final String device = Build.DEVICE;
|
|
||||||
|
|
||||||
private final String hardware = Build.HARDWARE;
|
|
||||||
|
|
||||||
private final boolean isAdaptive;
|
|
||||||
|
|
||||||
private final String manufacturer = Build.MANUFACTURER;
|
|
||||||
|
|
||||||
private final String model = Build.MODEL;
|
|
||||||
|
|
||||||
private final String nowPlayingTheme;
|
|
||||||
|
|
||||||
private final String product = Build.PRODUCT;
|
|
||||||
|
|
||||||
private final String releaseVersion = Build.VERSION.RELEASE;
|
|
||||||
|
|
||||||
@IntRange(from = 0)
|
|
||||||
private final int sdkVersion = Build.VERSION.SDK_INT;
|
|
||||||
|
|
||||||
private final int versionCode;
|
|
||||||
|
|
||||||
private final String versionName;
|
|
||||||
private final String selectedLang;
|
|
||||||
|
|
||||||
public DeviceInfo(Context context) {
|
|
||||||
PackageInfo packageInfo;
|
|
||||||
try {
|
|
||||||
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
packageInfo = null;
|
|
||||||
}
|
|
||||||
if (packageInfo != null) {
|
|
||||||
versionCode = packageInfo.versionCode;
|
|
||||||
versionName = packageInfo.versionName;
|
|
||||||
} else {
|
|
||||||
versionCode = -1;
|
|
||||||
versionName = null;
|
|
||||||
}
|
|
||||||
baseTheme = PreferenceUtil.INSTANCE.getBaseTheme();
|
|
||||||
nowPlayingTheme =
|
|
||||||
context.getString(PreferenceUtil.INSTANCE.getNowPlayingScreen().getTitleRes());
|
|
||||||
isAdaptive = PreferenceUtil.INSTANCE.isAdaptiveColor();
|
|
||||||
selectedLang = PreferenceUtil.INSTANCE.getLanguageCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toMarkdown() {
|
|
||||||
return "Device info:\n"
|
|
||||||
+ "---\n"
|
|
||||||
+ "<table>\n"
|
|
||||||
+ "<tr><td><b>App version</b></td><td>"
|
|
||||||
+ versionName
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>App version code</td><td>"
|
|
||||||
+ versionCode
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Android build version</td><td>"
|
|
||||||
+ buildVersion
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Android release version</td><td>"
|
|
||||||
+ releaseVersion
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Android SDK version</td><td>"
|
|
||||||
+ sdkVersion
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Android build ID</td><td>"
|
|
||||||
+ buildID
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Device brand</td><td>"
|
|
||||||
+ brand
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Device manufacturer</td><td>"
|
|
||||||
+ manufacturer
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Device name</td><td>"
|
|
||||||
+ device
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Device model</td><td>"
|
|
||||||
+ model
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Device product name</td><td>"
|
|
||||||
+ product
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Device hardware name</td><td>"
|
|
||||||
+ hardware
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>ABIs</td><td>"
|
|
||||||
+ Arrays.toString(abis)
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>ABIs (32bit)</td><td>"
|
|
||||||
+ Arrays.toString(abis32Bits)
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>ABIs (64bit)</td><td>"
|
|
||||||
+ Arrays.toString(abis64Bits)
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "<tr><td>Language</td><td>"
|
|
||||||
+ selectedLang
|
|
||||||
+ "</td></tr>\n"
|
|
||||||
+ "</table>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "App version: "
|
|
||||||
+ versionName
|
|
||||||
+ "\n"
|
|
||||||
+ "App version code: "
|
|
||||||
+ versionCode
|
|
||||||
+ "\n"
|
|
||||||
+ "Android build version: "
|
|
||||||
+ buildVersion
|
|
||||||
+ "\n"
|
|
||||||
+ "Android release version: "
|
|
||||||
+ releaseVersion
|
|
||||||
+ "\n"
|
|
||||||
+ "Android SDK version: "
|
|
||||||
+ sdkVersion
|
|
||||||
+ "\n"
|
|
||||||
+ "Android build ID: "
|
|
||||||
+ buildID
|
|
||||||
+ "\n"
|
|
||||||
+ "Device brand: "
|
|
||||||
+ brand
|
|
||||||
+ "\n"
|
|
||||||
+ "Device manufacturer: "
|
|
||||||
+ manufacturer
|
|
||||||
+ "\n"
|
|
||||||
+ "Device name: "
|
|
||||||
+ device
|
|
||||||
+ "\n"
|
|
||||||
+ "Device model: "
|
|
||||||
+ model
|
|
||||||
+ "\n"
|
|
||||||
+ "Device product name: "
|
|
||||||
+ product
|
|
||||||
+ "\n"
|
|
||||||
+ "Device hardware name: "
|
|
||||||
+ hardware
|
|
||||||
+ "\n"
|
|
||||||
+ "ABIs: "
|
|
||||||
+ Arrays.toString(abis)
|
|
||||||
+ "\n"
|
|
||||||
+ "ABIs (32bit): "
|
|
||||||
+ Arrays.toString(abis32Bits)
|
|
||||||
+ "\n"
|
|
||||||
+ "ABIs (64bit): "
|
|
||||||
+ Arrays.toString(abis64Bits)
|
|
||||||
+ "\n"
|
|
||||||
+ "Base theme: "
|
|
||||||
+ baseTheme
|
|
||||||
+ "\n"
|
|
||||||
+ "Now playing theme: "
|
|
||||||
+ nowPlayingTheme
|
|
||||||
+ "\n"
|
|
||||||
+ "Adaptive: "
|
|
||||||
+ isAdaptive
|
|
||||||
+ "\n"
|
|
||||||
+ "System language: "
|
|
||||||
+ Locale.getDefault().toLanguageTag()
|
|
||||||
+ "\n"
|
|
||||||
+ "In-App Language: "
|
|
||||||
+ selectedLang;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
package code.name.monkey.retromusic.activities.bugreport.model
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.IntRange
|
||||||
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
import code.name.monkey.retromusic.util.PreferenceUtil.isAdaptiveColor
|
||||||
|
import code.name.monkey.retromusic.util.PreferenceUtil.languageCode
|
||||||
|
import code.name.monkey.retromusic.util.PreferenceUtil.nowPlayingScreen
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class DeviceInfo(context: Context) {
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private val abis = Build.SUPPORTED_ABIS
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private val abis32Bits = Build.SUPPORTED_32_BIT_ABIS
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private val abis64Bits = Build.SUPPORTED_64_BIT_ABIS
|
||||||
|
private val baseTheme: String
|
||||||
|
private val brand = Build.BRAND
|
||||||
|
private val buildID = Build.DISPLAY
|
||||||
|
private val buildVersion = Build.VERSION.INCREMENTAL
|
||||||
|
private val device = Build.DEVICE
|
||||||
|
private val hardware = Build.HARDWARE
|
||||||
|
private val isAdaptive: Boolean
|
||||||
|
private val manufacturer = Build.MANUFACTURER
|
||||||
|
private val model = Build.MODEL
|
||||||
|
private val nowPlayingTheme: String
|
||||||
|
private val product = Build.PRODUCT
|
||||||
|
private val releaseVersion = Build.VERSION.RELEASE
|
||||||
|
|
||||||
|
@IntRange(from = 0)
|
||||||
|
private val sdkVersion = Build.VERSION.SDK_INT
|
||||||
|
private var versionCode = 0
|
||||||
|
private var versionName: String? = null
|
||||||
|
private val selectedLang: String
|
||||||
|
fun toMarkdown(): String {
|
||||||
|
return """
|
||||||
|
Device info:
|
||||||
|
---
|
||||||
|
<table>
|
||||||
|
<tr><td><b>App version</b></td><td>$versionName</td></tr>
|
||||||
|
<tr><td>App version code</td><td>$versionCode</td></tr>
|
||||||
|
<tr><td>Android build version</td><td>$buildVersion</td></tr>
|
||||||
|
<tr><td>Android release version</td><td>$releaseVersion</td></tr>
|
||||||
|
<tr><td>Android SDK version</td><td>$sdkVersion</td></tr>
|
||||||
|
<tr><td>Android build ID</td><td>$buildID</td></tr>
|
||||||
|
<tr><td>Device brand</td><td>$brand</td></tr>
|
||||||
|
<tr><td>Device manufacturer</td><td>$manufacturer</td></tr>
|
||||||
|
<tr><td>Device name</td><td>$device</td></tr>
|
||||||
|
<tr><td>Device model</td><td>$model</td></tr>
|
||||||
|
<tr><td>Device product name</td><td>$product</td></tr>
|
||||||
|
<tr><td>Device hardware name</td><td>$hardware</td></tr>
|
||||||
|
<tr><td>ABIs</td><td>${Arrays.toString(abis)}</td></tr>
|
||||||
|
<tr><td>ABIs (32bit)</td><td>${Arrays.toString(abis32Bits)}</td></tr>
|
||||||
|
<tr><td>ABIs (64bit)</td><td>${Arrays.toString(abis64Bits)}</td></tr>
|
||||||
|
<tr><td>Language</td><td>$selectedLang</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return """
|
||||||
|
App version: $versionName
|
||||||
|
App version code: $versionCode
|
||||||
|
Android build version: $buildVersion
|
||||||
|
Android release version: $releaseVersion
|
||||||
|
Android SDK version: $sdkVersion
|
||||||
|
Android build ID: $buildID
|
||||||
|
Device brand: $brand
|
||||||
|
Device manufacturer: $manufacturer
|
||||||
|
Device name: $device
|
||||||
|
Device model: $model
|
||||||
|
Device product name: $product
|
||||||
|
Device hardware name: $hardware
|
||||||
|
ABIs: ${Arrays.toString(abis)}
|
||||||
|
ABIs (32bit): ${Arrays.toString(abis32Bits)}
|
||||||
|
ABIs (64bit): ${Arrays.toString(abis64Bits)}
|
||||||
|
Base theme: $baseTheme
|
||||||
|
Now playing theme: $nowPlayingTheme
|
||||||
|
Adaptive: $isAdaptive
|
||||||
|
System language: ${Locale.getDefault().toLanguageTag()}
|
||||||
|
In-App Language: $selectedLang
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val packageInfo = try {
|
||||||
|
context.packageManager.getPackageInfo(context.packageName, 0)
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
if (packageInfo != null) {
|
||||||
|
versionCode = packageInfo.versionCode
|
||||||
|
versionName = packageInfo.versionName
|
||||||
|
} else {
|
||||||
|
versionCode = -1
|
||||||
|
versionName = null
|
||||||
|
}
|
||||||
|
baseTheme = PreferenceUtil.baseTheme
|
||||||
|
nowPlayingTheme = context.getString(nowPlayingScreen.titleRes)
|
||||||
|
isAdaptive = isAdaptiveColor
|
||||||
|
selectedLang = languageCode
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +0,0 @@
|
||||||
package code.name.monkey.retromusic.activities.bugreport.model;
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.activities.bugreport.model.github.ExtraInfo;
|
|
||||||
|
|
||||||
public class Report {
|
|
||||||
|
|
||||||
private final String description;
|
|
||||||
|
|
||||||
private final DeviceInfo deviceInfo;
|
|
||||||
|
|
||||||
private final ExtraInfo extraInfo;
|
|
||||||
|
|
||||||
private final String title;
|
|
||||||
|
|
||||||
public Report(String title, String description, DeviceInfo deviceInfo, ExtraInfo extraInfo) {
|
|
||||||
this.title = title;
|
|
||||||
this.description = description;
|
|
||||||
this.deviceInfo = deviceInfo;
|
|
||||||
this.extraInfo = extraInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description
|
|
||||||
+ "\n\n"
|
|
||||||
+ "-\n\n"
|
|
||||||
+ deviceInfo.toMarkdown()
|
|
||||||
+ "\n\n"
|
|
||||||
+ extraInfo.toMarkdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package code.name.monkey.retromusic.activities.bugreport.model
|
||||||
|
|
||||||
|
import code.name.monkey.retromusic.activities.bugreport.model.github.ExtraInfo
|
||||||
|
|
||||||
|
class Report(
|
||||||
|
val title: String,
|
||||||
|
private val description: String,
|
||||||
|
private val deviceInfo: DeviceInfo?,
|
||||||
|
private val extraInfo: ExtraInfo
|
||||||
|
) {
|
||||||
|
fun getDescription(): String {
|
||||||
|
return """
|
||||||
|
$description
|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
${deviceInfo?.toMarkdown()}
|
||||||
|
|
||||||
|
${extraInfo.toMarkdown()}
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,61 +0,0 @@
|
||||||
package code.name.monkey.retromusic.activities.bugreport.model.github;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ExtraInfo {
|
|
||||||
|
|
||||||
private final Map<String, String> extraInfo = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
public void put(String key, String value) {
|
|
||||||
extraInfo.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, boolean value) {
|
|
||||||
extraInfo.put(key, Boolean.toString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, double value) {
|
|
||||||
extraInfo.put(key, Double.toString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, float value) {
|
|
||||||
extraInfo.put(key, Float.toString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, long value) {
|
|
||||||
extraInfo.put(key, Long.toString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, int value) {
|
|
||||||
extraInfo.put(key, Integer.toString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, Object value) {
|
|
||||||
extraInfo.put(key, String.valueOf(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(String key) {
|
|
||||||
extraInfo.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toMarkdown() {
|
|
||||||
if (extraInfo.isEmpty()) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder output = new StringBuilder();
|
|
||||||
output.append("Extra info:\n" + "---\n" + "<table>\n");
|
|
||||||
for (String key : extraInfo.keySet()) {
|
|
||||||
output
|
|
||||||
.append("<tr><td>")
|
|
||||||
.append(key)
|
|
||||||
.append("</td><td>")
|
|
||||||
.append(extraInfo.get(key))
|
|
||||||
.append("</td></tr>\n");
|
|
||||||
}
|
|
||||||
output.append("</table>\n");
|
|
||||||
|
|
||||||
return output.toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package code.name.monkey.retromusic.activities.bugreport.model.github
|
||||||
|
|
||||||
|
class ExtraInfo {
|
||||||
|
private val extraInfo: MutableMap<String, String> = LinkedHashMap()
|
||||||
|
fun put(key: String, value: String) {
|
||||||
|
extraInfo[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun put(key: String, value: Boolean) {
|
||||||
|
extraInfo[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun put(key: String, value: Double) {
|
||||||
|
extraInfo[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun put(key: String, value: Float) {
|
||||||
|
extraInfo[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun put(key: String, value: Long) {
|
||||||
|
extraInfo[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun put(key: String, value: Int) {
|
||||||
|
extraInfo[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun put(key: String, value: Any) {
|
||||||
|
extraInfo[key] = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun remove(key: String) {
|
||||||
|
extraInfo.remove(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toMarkdown(): String {
|
||||||
|
if (extraInfo.isEmpty()) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
val output = StringBuilder()
|
||||||
|
output.append(
|
||||||
|
"""
|
||||||
|
Extra info:
|
||||||
|
---
|
||||||
|
<table>
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
for (key in extraInfo.keys) {
|
||||||
|
output
|
||||||
|
.append("<tr><td>")
|
||||||
|
.append(key)
|
||||||
|
.append("</td><td>")
|
||||||
|
.append(extraInfo[key])
|
||||||
|
.append("</td></tr>\n")
|
||||||
|
}
|
||||||
|
output.append("</table>\n")
|
||||||
|
return output.toString()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,40 +0,0 @@
|
||||||
package code.name.monkey.retromusic.activities.bugreport.model.github;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
public class GithubLogin {
|
|
||||||
|
|
||||||
private final String apiToken;
|
|
||||||
|
|
||||||
private final String password;
|
|
||||||
|
|
||||||
private final String username;
|
|
||||||
|
|
||||||
public GithubLogin(String username, String password) {
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
this.apiToken = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GithubLogin(String apiToken) {
|
|
||||||
this.username = null;
|
|
||||||
this.password = null;
|
|
||||||
this.apiToken = apiToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getApiToken() {
|
|
||||||
return apiToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldUseApiToken() {
|
|
||||||
return TextUtils.isEmpty(username) || TextUtils.isEmpty(password);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package code.name.monkey.retromusic.activities.bugreport.model.github
|
||||||
|
|
||||||
|
import android.text.TextUtils
|
||||||
|
|
||||||
|
class GithubLogin {
|
||||||
|
val apiToken: String?
|
||||||
|
val password: String?
|
||||||
|
val username: String?
|
||||||
|
|
||||||
|
constructor(username: String?, password: String?) {
|
||||||
|
this.username = username
|
||||||
|
this.password = password
|
||||||
|
apiToken = null
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(apiToken: String?) {
|
||||||
|
username = null
|
||||||
|
password = null
|
||||||
|
this.apiToken = apiToken
|
||||||
|
}
|
||||||
|
|
||||||
|
fun shouldUseApiToken(): Boolean {
|
||||||
|
return TextUtils.isEmpty(username) || TextUtils.isEmpty(password)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +0,0 @@
|
||||||
package code.name.monkey.retromusic.activities.bugreport.model.github;
|
|
||||||
|
|
||||||
public class GithubTarget {
|
|
||||||
|
|
||||||
private final String repository;
|
|
||||||
|
|
||||||
private final String username;
|
|
||||||
|
|
||||||
public GithubTarget(String username, String repository) {
|
|
||||||
this.username = username;
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRepository() {
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package code.name.monkey.retromusic.activities.bugreport.model.github
|
||||||
|
|
||||||
|
class GithubTarget(val username: String, val repository: String)
|
|
@ -51,7 +51,7 @@ class TagWriter {
|
||||||
|
|
||||||
suspend fun writeTagsToFiles(context: Context, info: AudioTagInfo) {
|
suspend fun writeTagsToFiles(context: Context, info: AudioTagInfo) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
kotlin.runCatching {
|
runCatching {
|
||||||
var artwork: Artwork? = null
|
var artwork: Artwork? = null
|
||||||
var albumArtFile: File? = null
|
var albumArtFile: File? = null
|
||||||
if (info.artworkInfo?.artwork != null) {
|
if (info.artworkInfo?.artwork != null) {
|
||||||
|
@ -124,7 +124,7 @@ class TagWriter {
|
||||||
suspend fun writeTagsToFilesR(context: Context, info: AudioTagInfo): List<File> =
|
suspend fun writeTagsToFilesR(context: Context, info: AudioTagInfo): List<File> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val cacheFiles = mutableListOf<File>()
|
val cacheFiles = mutableListOf<File>()
|
||||||
kotlin.runCatching {
|
runCatching {
|
||||||
var artwork: Artwork? = null
|
var artwork: Artwork? = null
|
||||||
var albumArtFile: File? = null
|
var albumArtFile: File? = null
|
||||||
if (info.artworkInfo?.artwork != null) {
|
if (info.artworkInfo?.artwork != null) {
|
||||||
|
|
|
@ -15,15 +15,9 @@
|
||||||
package code.name.monkey.retromusic.fragments.base
|
package code.name.monkey.retromusic.fragments.base
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
|
||||||
import code.name.monkey.retromusic.R
|
|
||||||
import code.name.monkey.retromusic.activities.MainActivity
|
import code.name.monkey.retromusic.activities.MainActivity
|
||||||
import code.name.monkey.retromusic.extensions.setLightStatusBarAuto
|
|
||||||
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
|
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
|
||||||
import code.name.monkey.retromusic.extensions.surfaceColor
|
|
||||||
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
||||||
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||||
|
|
||||||
|
@ -38,26 +32,4 @@ abstract class AbsMainActivityFragment(@LayoutRes layout: Int) : AbsMusicService
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
mainActivity.setTaskDescriptionColorAuto()
|
mainActivity.setTaskDescriptionColorAuto()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setStatusBarColor(view: View, color: Int) {
|
|
||||||
val statusBar = view.findViewById<View>(R.id.status_bar)
|
|
||||||
if (statusBar != null) {
|
|
||||||
if (VersionUtils.hasMarshmallow()) {
|
|
||||||
statusBar.setBackgroundColor(color)
|
|
||||||
mainActivity.setLightStatusBarAuto(color)
|
|
||||||
} else {
|
|
||||||
statusBar.setBackgroundColor(color)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setStatusBarColorAuto(view: View) {
|
|
||||||
val colorPrimary = surfaceColor()
|
|
||||||
// we don't want to use statusbar color because we are doing the color darkening on our own to support KitKat
|
|
||||||
if (VersionUtils.hasMarshmallow()) {
|
|
||||||
setStatusBarColor(view, colorPrimary)
|
|
||||||
} else {
|
|
||||||
setStatusBarColor(view, ColorUtil.darkenColor(colorPrimary))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,9 +220,9 @@ abstract class AbsPlayerControlsFragment(@LayoutRes layout: Int) : AbsMusicServi
|
||||||
childFragmentManager.beginTransaction()
|
childFragmentManager.beginTransaction()
|
||||||
.replace(R.id.volumeFragmentContainer, VolumeFragment()).commit()
|
.replace(R.id.volumeFragmentContainer, VolumeFragment()).commit()
|
||||||
childFragmentManager.executePendingTransactions()
|
childFragmentManager.executePendingTransactions()
|
||||||
volumeFragment =
|
|
||||||
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as? VolumeFragment
|
|
||||||
}
|
}
|
||||||
|
volumeFragment =
|
||||||
|
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as? VolumeFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
|
@ -137,7 +137,6 @@ class VolumeFragment : Fragment(), SeekBar.OnSeekBarChangeListener, OnAudioVolum
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance(): VolumeFragment {
|
fun newInstance(): VolumeFragment {
|
||||||
return VolumeFragment()
|
return VolumeFragment()
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,6 @@ class CardBlurFragment : AbsPlayerFragment(R.layout.fragment_card_blur_player),
|
||||||
super.onResume()
|
super.onResume()
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
.registerOnSharedPreferenceChangeListener(this)
|
.registerOnSharedPreferenceChangeListener(this)
|
||||||
lastRequest = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
|
|
@ -39,7 +39,6 @@ class ColorFragment : AbsPlayerFragment(R.layout.fragment_color_player) {
|
||||||
private var _binding: FragmentColorPlayerBinding? = null
|
private var _binding: FragmentColorPlayerBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
|
|
||||||
override fun playerToolbar(): Toolbar {
|
override fun playerToolbar(): Toolbar {
|
||||||
return binding.playerToolbar
|
return binding.playerToolbar
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* Licensed under the GNU General Public License v3
|
|
||||||
*
|
|
||||||
* This is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.volume;
|
|
||||||
|
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Handler;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
public class AudioVolumeContentObserver extends ContentObserver {
|
|
||||||
|
|
||||||
private final OnAudioVolumeChangedListener mListener;
|
|
||||||
|
|
||||||
private final AudioManager mAudioManager;
|
|
||||||
|
|
||||||
private final int mAudioStreamType;
|
|
||||||
|
|
||||||
private float mLastVolume;
|
|
||||||
|
|
||||||
AudioVolumeContentObserver(
|
|
||||||
@NonNull Handler handler,
|
|
||||||
@NonNull AudioManager audioManager,
|
|
||||||
int audioStreamType,
|
|
||||||
@NonNull OnAudioVolumeChangedListener listener) {
|
|
||||||
|
|
||||||
super(handler);
|
|
||||||
mAudioManager = audioManager;
|
|
||||||
mAudioStreamType = audioStreamType;
|
|
||||||
mListener = listener;
|
|
||||||
mLastVolume = audioManager.getStreamVolume(mAudioStreamType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Depending on the handler this method may be executed on the UI thread */
|
|
||||||
@Override
|
|
||||||
public void onChange(boolean selfChange, Uri uri) {
|
|
||||||
if (mAudioManager != null && mListener != null) {
|
|
||||||
int maxVolume = mAudioManager.getStreamMaxVolume(mAudioStreamType);
|
|
||||||
int currentVolume = mAudioManager.getStreamVolume(mAudioStreamType);
|
|
||||||
if (currentVolume != mLastVolume) {
|
|
||||||
mLastVolume = currentVolume;
|
|
||||||
mListener.onAudioVolumeChanged(currentVolume, maxVolume);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deliverSelfNotifications() {
|
|
||||||
return super.deliverSelfNotifications();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU General Public License v3
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
package code.name.monkey.retromusic.volume
|
||||||
|
|
||||||
|
import android.database.ContentObserver
|
||||||
|
import android.media.AudioManager
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
|
|
||||||
|
class AudioVolumeContentObserver internal constructor(
|
||||||
|
handler: Handler,
|
||||||
|
audioManager: AudioManager,
|
||||||
|
audioStreamType: Int,
|
||||||
|
listener: OnAudioVolumeChangedListener
|
||||||
|
) : ContentObserver(handler) {
|
||||||
|
private val mListener: OnAudioVolumeChangedListener?
|
||||||
|
private val mAudioManager: AudioManager?
|
||||||
|
private val mAudioStreamType: Int
|
||||||
|
private var mLastVolume: Float
|
||||||
|
|
||||||
|
/** Depending on the handler this method may be executed on the UI thread */
|
||||||
|
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
||||||
|
if (mAudioManager != null && mListener != null) {
|
||||||
|
val maxVolume = mAudioManager.getStreamMaxVolume(mAudioStreamType)
|
||||||
|
val currentVolume = mAudioManager.getStreamVolume(mAudioStreamType)
|
||||||
|
if (currentVolume.toFloat() != mLastVolume) {
|
||||||
|
mLastVolume = currentVolume.toFloat()
|
||||||
|
mListener.onAudioVolumeChanged(currentVolume, maxVolume)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
mAudioManager = audioManager
|
||||||
|
mAudioStreamType = audioStreamType
|
||||||
|
mListener = listener
|
||||||
|
mLastVolume = audioManager.getStreamVolume(mAudioStreamType).toFloat()
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="56dp"
|
android:layout_marginStart="56dp"
|
||||||
android:layout_marginLeft="56dp"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingBottom="8dp">
|
android:paddingBottom="8dp">
|
||||||
|
@ -54,9 +53,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingStart="72dp"
|
android:paddingStart="72dp"
|
||||||
android:paddingLeft="72dp"
|
android:paddingEnd="16dp">
|
||||||
android:paddingEnd="16dp"
|
|
||||||
android:paddingRight="16dp">
|
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -166,7 +163,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="56dp"
|
android:layout_marginStart="56dp"
|
||||||
android:layout_marginLeft="56dp"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingBottom="8dp">
|
android:paddingBottom="8dp">
|
||||||
|
|
|
@ -533,4 +533,5 @@
|
||||||
<string name="you_have_to_select_at_least_one_category">You have to select at least one category.</string>
|
<string name="you_have_to_select_at_least_one_category">You have to select at least one category.</string>
|
||||||
<string name="you_will_be_forwarded_to_the_issue_tracker_website">You will be forwarded to the issue tracker website.</string>
|
<string name="you_will_be_forwarded_to_the_issue_tracker_website">You will be forwarded to the issue tracker website.</string>
|
||||||
<string name="your_account_data_is_only_used_for_authentication">Your account data is only used for authentication.</string>
|
<string name="your_account_data_is_only_used_for_authentication">Your account data is only used for authentication.</string>
|
||||||
|
<string name="bug_report_success">Bug report successful</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue