Skip to content

Commit

Permalink
show only licence choosing dialog in record audio dialog #82
Browse files Browse the repository at this point in the history
  • Loading branch information
KanagasabapathyR committed Mar 5, 2023
1 parent 08370b6 commit 227fa4d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import android.app.Activity
import android.app.AlertDialog
import com.manimarank.spell4wiki.R
import com.manimarank.spell4wiki.data.prefs.AppPref
import com.manimarank.spell4wiki.data.prefs.PrefManager
import com.manimarank.spell4wiki.utils.WikiLicense
import kotlinx.android.synthetic.main.activity_record_audio_pop_up.*
import kotlinx.android.synthetic.main.activity_settings.*

object RecordInfoDialog {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ package com.manimarank.spell4wiki.ui.recordaudio

import android.Manifest
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import android.text.TextUtils
import android.text.method.LinkMovementMethod
import android.view.MotionEvent
import android.view.View
import android.webkit.MimeTypeMap
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.text.HtmlCompat
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import com.google.gson.Gson
import com.manimarank.spell4wiki.R
Expand All @@ -40,6 +45,7 @@ import com.manimarank.spell4wiki.record.ogg.WavToOggConverter
import com.manimarank.spell4wiki.record.wav.WAVPlayer
import com.manimarank.spell4wiki.record.wav.WAVRecorder
import com.manimarank.spell4wiki.ui.common.BaseActivity
import com.manimarank.spell4wiki.ui.dialogs.AppLanguageDialog
import com.manimarank.spell4wiki.ui.recordaudio.WikiDataUtils.getUploadName
import com.manimarank.spell4wiki.ui.settings.SettingsActivity
import com.manimarank.spell4wiki.utils.DateUtils.DF_YYYY_MM_DD
Expand All @@ -53,14 +59,17 @@ import com.manimarank.spell4wiki.utils.Print.error
import com.manimarank.spell4wiki.utils.Print.log
import com.manimarank.spell4wiki.utils.RealPathUtil
import com.manimarank.spell4wiki.utils.ToastUtils.showLong
import com.manimarank.spell4wiki.utils.WikiLicense
import com.manimarank.spell4wiki.utils.WikiLicense.getLicenseTemplateInWiki
import com.manimarank.spell4wiki.utils.WikiLicense.licenseNameId
import com.manimarank.spell4wiki.utils.constants.AppConstants
import com.manimarank.spell4wiki.utils.constants.AppConstants.MAX_RETRIES_FOR_CSRF_TOKEN
import com.manimarank.spell4wiki.utils.constants.AppConstants.MAX_RETRIES_FOR_FORCE_LOGIN
import com.manimarank.spell4wiki.utils.constants.AppConstants.RC_EDIT_REQUEST_CODE
import com.manimarank.spell4wiki.utils.constants.AppConstants.RC_LICENCE_CHANGE
import com.manimarank.spell4wiki.utils.extensions.showLicenseChooseDialog
import kotlinx.android.synthetic.main.activity_record_audio_pop_up.*
import kotlinx.android.synthetic.main.activity_settings.*
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
Expand Down Expand Up @@ -128,10 +137,22 @@ class RecordAudioActivity : BaseActivity() {
txtDuration.text = getDurationValue(0)
checkboxDeclaration.text = String.format(getString(R.string.declaration_note), getString(licenseNameId(pref.uploadAudioLicense)))



btnSettings.setOnClickListener {
startActivityForResult(Intent(applicationContext, SettingsActivity::class.java), RC_LICENCE_CHANGE)
showLicenseChooseDialog({
checkboxDeclaration.text = String.format(getString(R.string.declaration_note), getString(licenseNameId(pref.uploadAudioLicense)))
})

}



// btnSettings.setOnClickListener {
//
// startActivityForResult(Intent(applicationContext, SettingsActivity::class.java), RC_LICENCE_CHANGE)
// }

// Set 10 sec only for recording
countDownTimer = object : CountDownTimer(AppConstants.MAX_SEC_FOR_RECORDING * 1000, 1000) {
override fun onTick(millisUntilFinished: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ import com.manimarank.spell4wiki.ui.dialogs.AppLanguageDialog.getSelectedLanguag
import com.manimarank.spell4wiki.ui.dialogs.AppLanguageDialog.show
import com.manimarank.spell4wiki.ui.languageselector.LanguageSelectionFragment
import com.manimarank.spell4wiki.ui.listerners.OnLanguageSelectionListener
import com.manimarank.spell4wiki.ui.recordaudio.RecordAudioActivity
import com.manimarank.spell4wiki.utils.WikiLicense
import com.manimarank.spell4wiki.utils.WikiLicense.licenseNameId
import com.manimarank.spell4wiki.utils.WikiLicense.licenseUrlFor
import com.manimarank.spell4wiki.utils.constants.AppConstants
import com.manimarank.spell4wiki.utils.constants.ListMode
import com.manimarank.spell4wiki.utils.extensions.showLicenseChooseDialog
import com.manimarank.spell4wiki.utils.makeGone
import kotlinx.android.synthetic.main.activity_record_audio_pop_up.*
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*

Expand Down Expand Up @@ -91,34 +94,14 @@ class SettingsActivity : BaseActivity() {
languageSelectionFragment.show(supportFragmentManager)
}
updateLicenseView(txtLicenseOfUploadAudio, txtLicenseOfUploadAudioLegalCode)



layoutLicenseOfUploadAudio.setOnClickListener {
// setup the alert builder
val builder = AlertDialog.Builder(this)
builder.setTitle(R.string.license_choose_alert) // add a radio button list
val licensePrefList = arrayOf(
WikiLicense.LicensePrefs.CC_0,
WikiLicense.LicensePrefs.CC_BY_3,
WikiLicense.LicensePrefs.CC_BY_SA_3,
WikiLicense.LicensePrefs.CC_BY_4,
WikiLicense.LicensePrefs.CC_BY_SA_4
)
val licenseList = arrayOf(
getString(R.string.license_name_cc_zero),
getString(R.string.license_name_cc_by_three),
getString(R.string.license_name_cc_by_sa_three),
getString(R.string.license_name_cc_by_four),
getString(R.string.license_name_cc_by_sa_four)
)
val checkedItem = licensePrefList.indexOf(pref.uploadAudioLicense)
builder.setSingleChoiceItems(licenseList, checkedItem) { dialog: DialogInterface, which: Int ->
pref.uploadAudioLicense = licensePrefList[which]
showLicenseChooseDialog {
updateLicenseView(txtLicenseOfUploadAudio, txtLicenseOfUploadAudioLegalCode)
dialog.dismiss()
}
builder.setNegativeButton(getString(R.string.cancel), null)
val dialog = builder.create()
dialog.show()
}
} }

txtAppLanguage.text = getSelectedLanguage()
layoutLanguageOfApp.setOnClickListener { show(this@SettingsActivity) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.manimarank.spell4wiki.utils.extensions

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface
import android.os.Build
import com.manimarank.spell4wiki.R
import com.manimarank.spell4wiki.data.prefs.PrefManager
import com.manimarank.spell4wiki.utils.WikiLicense
import kotlin.Exception as KotlinException

/**
Expand All @@ -20,4 +26,37 @@ fun Context.getAppVersion(): Long {
e.printStackTrace()
}
return versionCode
}

fun Activity.showLicenseChooseDialog(confirmAction: () -> Unit = {}) {
try {
val pref = PrefManager(this)
val builder = AlertDialog.Builder(this)
builder.setTitle(R.string.license_choose_alert) // add a radio button list
val licensePrefList = arrayOf(
WikiLicense.LicensePrefs.CC_0,
WikiLicense.LicensePrefs.CC_BY_3,
WikiLicense.LicensePrefs.CC_BY_SA_3,
WikiLicense.LicensePrefs.CC_BY_4,
WikiLicense.LicensePrefs.CC_BY_SA_4
)
val licenseList = arrayOf(
getString(R.string.license_name_cc_zero),
getString(R.string.license_name_cc_by_three),
getString(R.string.license_name_cc_by_sa_three),
getString(R.string.license_name_cc_by_four),
getString(R.string.license_name_cc_by_sa_four)
)
val checkedItem = licensePrefList.indexOf(pref.uploadAudioLicense)
builder.setSingleChoiceItems(licenseList, checkedItem) { dialog: DialogInterface, which: Int ->
pref.uploadAudioLicense = licensePrefList[which]
confirmAction()
dialog.dismiss()
}
builder.setNegativeButton(getString(R.string.cancel), null)
val dialog = builder.create()
dialog.show()
} catch (e: Exception) {
e.printStackTrace()
}
}

0 comments on commit 227fa4d

Please sign in to comment.