-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly functional location switch. convert to kotlin because studio i…
…s stupid. Automatic conversion also automatically stages the file, making it impossible to for me to separate changes I made before converting (which were going to be in a separate commit) and the conversion itself. Thanks, Obama.
- Loading branch information
Showing
69 changed files
with
4,488 additions
and
4,885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 0 additions & 181 deletions
181
app/src/main/java/com/jmstudios/redmoon/activity/AutomaticSuspendPreferenceActivity.java
This file was deleted.
Oops, something went wrong.
165 changes: 165 additions & 0 deletions
165
app/src/main/java/com/jmstudios/redmoon/activity/AutomaticSuspendPreferenceActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright (c) 2016 Marien Raat <marienraat@riseup.net> | ||
* | ||
* This file is free software: you may copy, redistribute 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 file 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. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.jmstudios.redmoon.activity | ||
|
||
import android.preference.Preference | ||
import android.preference.PreferenceActivity | ||
import android.preference.PreferenceScreen | ||
import android.preference.PreferenceManager | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.Menu | ||
import android.view.MenuInflater | ||
import android.view.MenuItem | ||
import android.content.res.Configuration | ||
import android.content.res.Resources | ||
import android.support.annotation.LayoutRes | ||
import android.content.Intent | ||
|
||
import android.support.v7.app.ActionBar | ||
import android.support.v7.app.AppCompatDelegate | ||
import android.support.v7.widget.Toolbar | ||
|
||
import com.jmstudios.redmoon.model.SettingsModel | ||
import com.jmstudios.redmoon.preference.SwitchBarPreference | ||
|
||
import com.jmstudios.redmoon.R | ||
|
||
class AutomaticSuspendPreferenceActivity : PreferenceActivity() { | ||
|
||
private var mDelegate: AppCompatDelegate? = null | ||
|
||
private var mSummaryPreference: Preference? = null | ||
private var mSwitchBarPreference: SwitchBarPreference? = null | ||
|
||
public override fun onCreate(savedInstanceState: Bundle?) { | ||
delegate.installViewFactory() | ||
delegate.onCreate(savedInstanceState) | ||
supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
|
||
super.onCreate(savedInstanceState) | ||
|
||
val preferenceScreen = preferenceManager.createPreferenceScreen(this) | ||
setPreferenceScreen(preferenceScreen) | ||
|
||
mSwitchBarPreference = SwitchBarPreference(this, this) | ||
mSwitchBarPreference!!.key = resources.getString(R.string.pref_key_automatic_suspend) | ||
preferenceScreen.addPreference(mSwitchBarPreference) | ||
|
||
mSummaryPreference = Preference(this) | ||
mSummaryPreference!!.layoutResource = R.layout.automatic_suspend_summary | ||
mSummaryPreference!!.isSelectable = false | ||
|
||
preferenceScreen.addPreference(mSummaryPreference) | ||
} | ||
|
||
override fun onApplyThemeResource(theme: Resources.Theme, resid: Int, first: Boolean) { | ||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) | ||
val settingsModel = SettingsModel(resources, sharedPreferences) | ||
|
||
if (settingsModel.darkThemeFlag) | ||
super.onApplyThemeResource(theme, R.style.AppThemeDark, first) | ||
else | ||
super.onApplyThemeResource(theme, resid, first) | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { | ||
when (requestCode) { | ||
RESULT_USAGE_ACCESS -> mSwitchBarPreference!!.usageStatsPermissionAttempted() | ||
} | ||
} | ||
|
||
override fun onPostCreate(savedInstanceState: Bundle?) { | ||
super.onPostCreate(savedInstanceState) | ||
delegate.onPostCreate(savedInstanceState) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
finish() | ||
return true | ||
} | ||
|
||
val supportActionBar: ActionBar? | ||
get() = delegate.supportActionBar | ||
|
||
fun setSupportActionBar(toolbar: Toolbar?) { | ||
delegate.setSupportActionBar(toolbar) | ||
} | ||
|
||
override fun getMenuInflater(): MenuInflater { | ||
return delegate.menuInflater | ||
} | ||
|
||
override fun setContentView(@LayoutRes layoutResID: Int) { | ||
delegate.setContentView(layoutResID) | ||
} | ||
|
||
override fun setContentView(view: View) { | ||
delegate.setContentView(view) | ||
} | ||
|
||
override fun setContentView(view: View, params: ViewGroup.LayoutParams) { | ||
delegate.setContentView(view, params) | ||
} | ||
|
||
override fun addContentView(view: View, params: ViewGroup.LayoutParams) { | ||
delegate.addContentView(view, params) | ||
} | ||
|
||
override fun onPostResume() { | ||
super.onPostResume() | ||
delegate.onPostResume() | ||
} | ||
|
||
override fun onTitleChanged(title: CharSequence, color: Int) { | ||
super.onTitleChanged(title, color) | ||
delegate.setTitle(title) | ||
} | ||
|
||
override fun onConfigurationChanged(newConfig: Configuration) { | ||
super.onConfigurationChanged(newConfig) | ||
delegate.onConfigurationChanged(newConfig) | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
delegate.onStop() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
delegate.onDestroy() | ||
} | ||
|
||
override fun invalidateOptionsMenu() { | ||
delegate.invalidateOptionsMenu() | ||
} | ||
|
||
private val delegate: AppCompatDelegate | ||
get() { | ||
if (mDelegate == null) { | ||
mDelegate = AppCompatDelegate.create(this, null) | ||
} | ||
return mDelegate!! | ||
} | ||
|
||
companion object { | ||
val RESULT_USAGE_ACCESS = 1 | ||
} | ||
} |
Oops, something went wrong.