fix copying API token

This commit is contained in:
Phillip Thelen 2019-06-25 17:40:30 -04:00
parent 4454c70d34
commit 1c4313f254
2 changed files with 10 additions and 10 deletions

View file

@ -95,15 +95,6 @@
android:shouldDisableView="false"
android:summary="@string/SP_APIToken_summary"
android:layout="@layout/preference_child_summary"/>
<Preference
android:key="SP_user_qr_code"
android:title="@string/SP_user_qr_code"
android:selectable="true"
android:persistent="false"
android:shouldDisableView="false"
android:summary="@string/SP_user_qr_code"
android:layout="@layout/preference_child_summary"/>
</PreferenceScreen>
<Preference

View file

@ -8,9 +8,14 @@ import android.widget.Toast
import androidx.preference.Preference
import com.habitrpg.android.habitica.HabiticaBaseApplication
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.api.HostConfig
import java.util.*
import javax.inject.Inject
class APIPreferenceFragment: BasePreferencesFragment() {
@Inject
lateinit var hostConfig: HostConfig
private val apiPreferences: List<String>
get() = Arrays.asList(getString(R.string.SP_APIToken), getString(R.string.SP_userID))
@ -22,7 +27,11 @@ class APIPreferenceFragment: BasePreferencesFragment() {
override fun onPreferenceTreeClick(preference: Preference): Boolean {
val clipMan = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
clipMan?.primaryClip = ClipData.newPlainText(preference.key, preference.summary)
if (preference.key == getString(R.string.SP_APIToken)) {
clipMan?.primaryClip = ClipData.newPlainText(preference.key, hostConfig.apiKey)
} else {
clipMan?.primaryClip = ClipData.newPlainText(preference.key, preference.summary)
}
Toast.makeText(activity, "Copied " + preference.key + " to clipboard.", Toast.LENGTH_SHORT).show()
return super.onPreferenceTreeClick(preference)
}