Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Revert UI change & bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kmod-midori committed Feb 25, 2017
1 parent 6ddcd66 commit 858ff6b
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 92 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "moe.reimu.weiboxposed"
minSdkVersion 17
targetSdkVersion 25
versionCode 11
versionName "1.5.3"
versionCode 13
versionName "1.5.4"
}
buildTypes {
release {
Expand All @@ -29,7 +29,6 @@ dependencies {
provided 'de.robv.android.xposed:api:82'
provided 'de.robv.android.xposed:api:82:sources'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:preference-v7:25.2.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

Expand Down
3 changes: 2 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
-keep public class moe.reimu.weiboxposed.Module
-keepclassmembernames class moe.reimu.weiboxposed.GeneralPreferenceFragment {
boolean isModuleEnabled();
}
}
-keepnames class moe.reimu.weiboxposed.*
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,30 @@ package moe.reimu.weiboxposed
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Bundle
import android.support.v7.preference.PreferenceFragmentCompat
import android.preference.PreferenceFragment
import android.widget.Toast
import java.net.URLEncoder

class GeneralPreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener {
class GeneralPreferenceFragment : PreferenceFragment() {
companion object {
val PREF_NAME = "prefs"
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
Toast.makeText(context, R.string.restart_weibo, Toast.LENGTH_SHORT).show()
}

@Suppress("DEPRECATION")
@SuppressLint("WorldReadableFiles")
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
context.getSharedPreferences(PREF_NAME, Context.MODE_WORLD_READABLE)
.registerOnSharedPreferenceChangeListener(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val manager = preferenceManager
manager.sharedPreferencesMode = Context.MODE_WORLD_READABLE
manager.sharedPreferencesName = PREF_NAME


if (!isModuleEnabled()) {
Toast.makeText(context, R.string.module_not_enabled, Toast.LENGTH_LONG).show()
Toast.makeText(activity, R.string.module_not_enabled, Toast.LENGTH_LONG).show()
}

addPreferencesFromResource(R.xml.pref_general)
Expand All @@ -43,7 +38,7 @@ class GeneralPreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.
val uri = Uri.parse("$alipayqr&%3F_s%3Dweb-other&_t=${System.currentTimeMillis()}")
val intent = Intent(Intent.ACTION_VIEW, uri)
try {
context.startActivity(intent)
activity.startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
24 changes: 16 additions & 8 deletions app/src/main/kotlin/moe/reimu/weiboxposed/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage, IXposedH
try {
val promotion = getObjectField(mblog, "promotion")

val title = getObjectField(mblog, "title")
// val title = getObjectField(mblog, "title")

if (promotion != null) {
val ad_type = getObjectField(promotion, "adtype") as String?
Expand All @@ -94,10 +94,10 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage, IXposedH
}
}

if (title != null) {
logd("detected promotion: title")
return true
}
// if (title != null) {
// logd("detected promotion: title")
// return true
// }

} catch (e: NoSuchFieldError) {
log(e.message!!)
Expand Down Expand Up @@ -275,7 +275,10 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage, IXposedH
}

private fun hookWeibo(lpparam: XC_LoadPackage.LoadPackageParam) {
reloadPrefs()
if (!reloadPrefs()){
log("Module disabled")
return
}
hookAD(lpparam)
hookGreyScale(lpparam)

Expand All @@ -287,14 +290,17 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage, IXposedH

}

private fun reloadPrefs() {
private fun reloadPrefs() : Boolean{
prefs.reload()
log("loaded")
debug_mode = prefs.getBoolean("debug_mode", false)
if (debug_mode) {
dumpPrefs()
}

if (!prefs.getBoolean("global_enabled", true)) {
return false
}

disabled_feature.clear()
disabled_feature.add("gif_video_player")
disabled_feature.add("ad_pull_refresh_enable")
Expand All @@ -309,6 +315,8 @@ class Module : IXposedHookInitPackageResources, IXposedHookLoadPackage, IXposedH

user_keyword = prefs.getString("user_keyword", "").split("\n")
user_keyword = user_keyword.filter(String::isNotBlank)
log("loaded")
return true
}

private fun openUrl(url: Uri) {
Expand Down
25 changes: 21 additions & 4 deletions app/src/main/kotlin/moe/reimu/weiboxposed/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package moe.reimu.weiboxposed

import android.support.v4.app.Fragment
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.preference.PreferenceActivity
import android.os.Bundle
import android.widget.Toast

class SettingsActivity : SingleFragmentActivity() {
override fun createFragment(): Fragment {
return GeneralPreferenceFragment()
class SettingsActivity : PreferenceActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
@Suppress("DEPRECATION")
@SuppressLint("WorldReadableFiles")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getSharedPreferences(GeneralPreferenceFragment.PREF_NAME, MODE_WORLD_READABLE)
.registerOnSharedPreferenceChangeListener(this)
fragmentManager.beginTransaction().replace(android.R.id.content, GeneralPreferenceFragment()).commit()
}

override fun isValidFragment(fragmentName: String): Boolean {
return GeneralPreferenceFragment::class.java.name == fragmentName
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
Toast.makeText(this, R.string.restart_weibo, Toast.LENGTH_SHORT).show()
}
}

This file was deleted.

8 changes: 0 additions & 8 deletions app/src/main/res/layout/activity_fragment.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="title_activity_settings">设置</string>

<string name="pref_features_title">功能</string>
<string name="pref_title_global_enabled">启用模块</string>
<string name="pref_title_remove_hot">去除已关注内容</string>
<string name="pref_description_remove_hot">包含来自已经关注用户的“粉丝头条”等推广内容</string>
<string name="pref_title_force_browser">强制使用外置浏览器</string>
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,5 @@
<item name="colorPrimary">#F44336</item>
<item name="colorPrimaryDark">#C62828</item>
<item name="colorAccent">#4CAF50</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
<style name="PreferenceThemeOverlay">
<item name="preferenceScreenStyle">@style/Preference.PreferenceScreen</item>
<item name="preferenceFragmentStyle">@style/PreferenceFragment</item>
<item name="preferenceCategoryStyle">@style/Preference.Category</item>
<item name="preferenceStyle">@style/Preference</item>
<item name="preferenceInformationStyle">@style/Preference.Information</item>
<item name="checkBoxPreferenceStyle">@style/Preference.CheckBoxPreference</item>
<item name="switchPreferenceCompatStyle">@style/Preference.SwitchPreferenceCompat</item>
<item name="dialogPreferenceStyle">@style/Preference.DialogPreference</item>
<item name="editTextPreferenceStyle">@style/Preference.DialogPreference.EditTextPreference</item>
<item name="preferenceFragmentListStyle">@style/PreferenceFragmentList</item>
</style>
</resources>
35 changes: 20 additions & 15 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.v7.preference.PreferenceCategory
<PreferenceCategory
android:key="features"
android:title="@string/pref_features_title">

<android.support.v7.preference.SwitchPreferenceCompat
<SwitchPreference
android:defaultValue="true"
android:key="global_enabled"
android:title="@string/pref_title_global_enabled"/>

<SwitchPreference
android:defaultValue="false"
android:key="remove_hot"
android:title="@string/pref_title_remove_hot"
android:summary="@string/pref_description_remove_hot"/>

<android.support.v7.preference.SwitchPreferenceCompat
<SwitchPreference
android:defaultValue="false"
android:key="force_browser"
android:summary="@string/pref_description_force_browser"
android:title="@string/pref_title_force_browser"/>

<android.support.v7.preference.SwitchPreferenceCompat
<SwitchPreference
android:defaultValue="false"
android:key="disable_new_message_flow"
android:title="@string/pref_title_disable_new_message_flow"/>

<android.support.v7.preference.SwitchPreferenceCompat
<SwitchPreference
android:defaultValue="false"
android:key="debug_mode"
android:title="@string/pref_title_debug_mode"/>
</android.support.v7.preference.PreferenceCategory>
</PreferenceCategory>

<android.support.v7.preference.PreferenceCategory
<PreferenceCategory
android:key="filtering"
android:title="@string/pref_filtering_title">
<android.support.v7.preference.EditTextPreference
<EditTextPreference
android:defaultValue=""
android:key="content_keyword"
android:title="@string/pref_title_content_keyword"/>
<android.support.v7.preference.EditTextPreference
<EditTextPreference
android:defaultValue=""
android:key="user_keyword"
android:title="@string/pref_title_user_keyword"/>
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_donate_title">
<android.support.v7.preference.Preference
<Preference
android:key="alipay"
android:title="@string/pref_title_alipay"/>
</android.support.v7.preference.PreferenceCategory>
</PreferenceCategory>

</android.support.v7.preference.PreferenceScreen>
</PreferenceScreen>

0 comments on commit 858ff6b

Please sign in to comment.