Skip to content

Commit

Permalink
Mostly functional location switch. convert to kotlin because studio i…
Browse files Browse the repository at this point in the history
…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
smichel17 committed Nov 11, 2016
1 parent 52a4c39 commit ed27961
Show file tree
Hide file tree
Showing 69 changed files with 4,488 additions and 4,885 deletions.
Expand Up @@ -13,16 +13,12 @@
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
package com.jmstudios.redmoon;
package com.jmstudios.redmoon

import android.app.Application;
import android.test.ApplicationTestCase;
import android.app.Application
import android.test.ApplicationTestCase

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
* [Testing Fundamentals](http://d.android.com/tools/testing/testing_android.html)
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
class ApplicationTest : ApplicationTestCase<Application>(Application::class.java)

This file was deleted.

@@ -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
}
}

0 comments on commit ed27961

Please sign in to comment.