Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bannedbook committed Aug 24, 2020
1 parent 1c71094 commit 957ab2c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 139 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
compileSdkVersion = 29
buildToolsVersion = '29.0.3'
desugarLibsVersion = '1.0.5'
versionCode = 445
versionName = '5.0.6.12R'
versionCode = 446
versionName = '5.0.6.13R'
resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW']
}

Expand Down
2 changes: 1 addition & 1 deletion gitupdate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ git pull origin master
git add -A
git commit -m "update"
git push origin master
git tag -a v5.0.6.12 -m "release v5.0.6.12"
git tag -a v5.0.6.13 -m "release v5.0.6.13"
git push origin --tags
pause
4 changes: 2 additions & 2 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</intent-filter>
</activity>

<activity
<!-- <activity
android:name=".Shortcut"
android:excludeFromRecents="true"
android:label="@string/quick_toggle"
Expand All @@ -64,7 +64,7 @@
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
</activity>
</activity>-->

<service
android:name=".bg.TileService"
Expand Down
69 changes: 40 additions & 29 deletions mobile/src/main/java/com/github/shadowsocks/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ import com.github.shadowsocks.utils.getBitmap
import com.github.shadowsocks.widget.ListHolderListener
import com.github.shadowsocks.widget.ServiceButton
import com.github.shadowsocks.widget.StatsBar
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.InterstitialAd
import com.google.android.gms.ads.MobileAds
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
Expand All @@ -70,6 +73,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
private const val REQUEST_CONNECT = 1

var stateListener: ((BaseService.State) -> Unit)? = null
@JvmStatic var newsClickCount = 1L
}

// UI
Expand Down Expand Up @@ -135,29 +139,6 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
else -> Core.startService()
}

private fun updateShortcuts() {
fun getIcon(id: Int): IconCompat = if (Build.VERSION.SDK_INT >= 26)
IconCompat.createWithAdaptiveBitmap(getBitmap(id))
else IconCompat.createWithBitmap(getBitmap(id))

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
val shortcutManager = getSystemService<ShortcutManager>(ShortcutManager::class.java)
val toggle = ShortcutInfoCompat.Builder(this, Shortcut.SHORTCUT_TOGGLE)
.setIntent(Intent(this, Shortcut::class.java).setAction(Shortcut.SHORTCUT_TOGGLE))
.setIcon(getIcon(R.drawable.ic_qu_shadowsocks_launcher))
.setShortLabel(Core.app.getString(R.string.quick_toggle))
.build()
.toShortcutInfo()
val scan = ShortcutInfoCompat.Builder(this, Shortcut.SHORTCUT_SCAN)
.setIntent(Intent(this, Shortcut::class.java).setAction(Shortcut.SHORTCUT_SCAN))
.setIcon(getIcon(R.drawable.ic_qu_camera_launcher))
.setShortLabel(Core.app.getString(R.string.add_profile_methods_scan_qr_code))
.build()
.toShortcutInfo()
shortcutManager?.dynamicShortcuts = listOf(toggle, scan)
}
}

private val handler = Handler()
private val connection = ShadowsocksConnection(handler, true)
override fun onServiceConnected(service: IShadowsocksService) = changeState(try {
Expand All @@ -182,6 +163,19 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
}
}
//lateinit var mAdView : AdView
lateinit var mInterstitialAd: InterstitialAd

fun userActionAds(){
if (newsClickCount%3==2L)mInterstitialAd.loadAd(AdRequest.Builder().build())
if (newsClickCount%3==1L && mInterstitialAd.isLoaded) {
Log.e("ads", "click count is $newsClickCount ,show ad.")
mInterstitialAd.show()
} else {
Log.e("ads", "click count is $newsClickCount ,The interstitial wasn't loaded yet.")
}
newsClickCount++
}

var prefs: SharedPreferences? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -195,10 +189,17 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
// val adRequest = AdRequest.Builder().build()
// mAdView.loadAd(adRequest)

mInterstitialAd = InterstitialAd(this)
mInterstitialAd.adUnitId = "ca-app-pub-2194043486084479/5146567707"
mInterstitialAd.loadAd(AdRequest.Builder().build())

snackbar = findViewById(R.id.snackbar)
snackbar.setOnApplyWindowInsetsListener(ListHolderListener)
stats = findViewById(R.id.stats)
stats.setOnClickListener { if (state == BaseService.State.Connected) stats.testConnection() }
stats.setOnClickListener {
userActionAds()
if (state == BaseService.State.Connected) stats.testConnection()
}
drawer = findViewById(R.id.drawer)
drawer.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
navigation = findViewById(R.id.navigation)
Expand All @@ -209,7 +210,10 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
}

fab = findViewById(R.id.fab)
fab.setOnClickListener { toggle() }
fab.setOnClickListener {
if(state.canStop)userActionAds()
toggle()
}
fab.setOnApplyWindowInsetsListener { view, insets ->
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = insets.systemWindowInsetBottom +
Expand All @@ -221,7 +225,6 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
changeState(BaseService.State.Idle) // reset everything to init state
connection.connect(this, this)
DataStore.publicStore.registerChangeListener(this)
updateShortcuts()
try {prefs = getSharedPreferences("free.ssr.proxy.SpeedUp.VPN", MODE_PRIVATE)}catch (e:Exception){}
//导入内置订阅
if(DataStore.isAutoUpdateServers)Core.updateBuiltinServers()
Expand All @@ -233,7 +236,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
// Do first run stuff here then set 'firstrun' as false
Core.alertMessage(getString(R.string.firstrun_tips), this,getString(R.string.firstrun_tips_title))
// using the following line to edit/commit prefs
prefs!!.edit().putBoolean("firstrun2", false).commit()
prefs!!.edit().putBoolean("firstrun2", false).apply()
}
}catch (e:Throwable){}
}
Expand All @@ -255,18 +258,26 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
if (item.isChecked) drawer.closeDrawers() else {
when (item.itemId) {
R.id.profiles -> {
//userActionAds()
displayFragment(ProfilesFragment())
connection.bandwidthTimeout = connection.bandwidthTimeout // request stats update
}
R.id.globalSettings -> displayFragment(GlobalSettingsFragment())
R.id.globalSettings -> {
userActionAds()
displayFragment(GlobalSettingsFragment())
}
R.id.about -> {
userActionAds()
displayFragment(AboutFragment())
}
R.id.faq -> {
launchUrl(getString(R.string.faq_url))
return true
}
R.id.subscriptions -> displayFragment(SubscriptionFragment())
R.id.subscriptions -> {
userActionAds()
displayFragment(SubscriptionFragment())
}
else -> return false
}
item.isChecked = true
Expand Down
19 changes: 18 additions & 1 deletion mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,20 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {

init {
edit.setOnClickListener {
(activity as MainActivity).userActionAds()
item = ProfileManager.getProfile(item.id)!!
startConfig(item)
}
subscription.setOnClickListener {
(activity as MainActivity).userActionAds()
item = ProfileManager.getProfile(item.id)!!
startConfig(item)
}
TooltipCompat.setTooltipText(edit, edit.contentDescription)
TooltipCompat.setTooltipText(subscription, subscription.contentDescription)
itemView.setOnClickListener(this)
share.setOnClickListener {
(activity as MainActivity).userActionAds()
val popup = PopupMenu(requireContext(), share)
popup.menuInflater.inflate(R.menu.profile_share_popup, popup.menu)
popup.setOnMenuItemClickListener(this)
Expand Down Expand Up @@ -360,10 +363,12 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {

override fun onMenuItemClick(item: MenuItem): Boolean = when (item.itemId) {
R.id.action_qr_code -> {
(activity as MainActivity).userActionAds()
QRCodeDialog(this.item.toString()).showAllowingStateLoss(parentFragmentManager)
true
}
R.id.action_export_clipboard -> {
(activity as MainActivity).userActionAds()
clipboard.setPrimaryClip(ClipData.newPlainText(null, this.item.toString()))
true
}
Expand Down Expand Up @@ -569,14 +574,17 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
override fun onMenuItemClick(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.update_servers -> {
(activity as MainActivity).userActionAds()
Core.updateBuiltinServers(activity)
true
}
R.id.action_scan_qr_code -> {
(activity as MainActivity).userActionAds()
startActivity(Intent(context, ScannerActivity::class.java))
true
}
R.id.action_import_clipboard -> {
(activity as MainActivity).userActionAds()
try {
val profiles = Profile.findAllUrls(
clipboard.primaryClip!!.getItemAt(0).text,
Expand All @@ -594,6 +602,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true
}
R.id.action_import_file -> {
(activity as MainActivity).userActionAds()
startFilesForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
type = "application/*"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
Expand All @@ -602,6 +611,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true
}
R.id.action_replace_file -> {
(activity as MainActivity).userActionAds()
startFilesForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
type = "application/*"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
Expand All @@ -610,11 +620,13 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true
}
R.id.action_manual_settings -> {
(activity as MainActivity).userActionAds()
startConfig(ProfileManager.createProfile(
Profile().also { Core.currentProfile?.first?.copyFeatureSettingsTo(it, true) }))
true
}
R.id.action_export_clipboard -> {
(activity as MainActivity).userActionAds()
val profiles = ProfileManager.getAllProfilesIgnoreGroup(VpnEncrypt.vpnGroupName)
(activity as MainActivity).snackbar().setText(if (profiles != null) {
clipboard.setPrimaryClip(ClipData.newPlainText(null, profiles.joinToString("\n")))
Expand All @@ -623,6 +635,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true
}
R.id.action_export_file -> {
(activity as MainActivity).userActionAds()
startFilesForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
type = "application/json"
putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited
Expand All @@ -631,6 +644,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
}

R.id.ping_all -> {
(activity as MainActivity).userActionAds()
for (element in profilesAdapter.profiles) {
element.elapsed = 0
}
Expand All @@ -639,7 +653,6 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
for (k in 0 until profilesAdapter.profiles.size) {
GlobalScope.launch {
try {
Log.e("tcping", "$k")
profilesAdapter.profiles[k].elapsed = tcping(profilesAdapter.profiles[k].host, profilesAdapter.profiles[k].remotePort)
ProfileManager.updateProfile(profilesAdapter.profiles[k])
Log.e("tcping", "$k - " + profilesAdapter.profiles[k].elapsed)
Expand All @@ -655,16 +668,19 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
}

R.id.real_ping_all -> {
(activity as MainActivity).userActionAds()
realTestProfiles(false)
true
}

R.id.retest_invalid_servers -> {
(activity as MainActivity).userActionAds()
realTestProfiles(true)
true
}

R.id.remove_invalid_servers -> {
(activity as MainActivity).userActionAds()
try {
for (k in profilesAdapter.profiles.size - 1 downTo 0) {
if (profilesAdapter.profiles[k].elapsed == -1L) {
Expand All @@ -683,6 +699,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
}

R.id.sort_servers_by_speed -> {
(activity as MainActivity).userActionAds()
try {
profilesAdapter.profiles.sortBy { it.elapsed }
//configs.vmess.reverse()
Expand Down
Loading

0 comments on commit 957ab2c

Please sign in to comment.