Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Merge pull request #2 from itning/dev_1.3
Browse files Browse the repository at this point in the history
1.3 Release
  • Loading branch information
itning authored Aug 12, 2020
2 parents 86f088c + 89af75d commit 5ef13d8
Show file tree
Hide file tree
Showing 31 changed files with 1,082 additions and 192 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "top.itning.getupearly"
minSdkVersion 21
targetSdkVersion 29
versionCode 3
versionName "1.2"
versionCode 5
versionName "1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "zh", "en"
}
Expand All @@ -31,9 +31,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'cat.ereza:customactivityoncrash:2.2.0'
implementation "androidx.recyclerview:recyclerview:1.1.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.ViewSettingActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
153 changes: 18 additions & 135 deletions app/src/main/java/top/itning/getupearly/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,26 @@
package top.itning.getupearly;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import top.itning.getupearly.config.SharedPreferencesConfig;
import top.itning.getupearly.factory.ViewFactory;
import top.itning.getupearly.strategy.StrategyContext;
import top.itning.getupearly.strategy.impl.UrlSchemeStrategy;
import top.itning.getupearly.ui.ViewSettingActivity;


/**
* @author itning
*/
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
/**
* 使用QQ内置浏览器URL模板
*/
private static final String QQ_BROWSER_URL_TEMPLATE = "mqqapi://forward/url?url_prefix=%s&souce=oicqzone.com&version=1&src_type=web";
/**
* 蚂蚁森林
*/
private static final String ALI_TREE_URL_SCHEME = "alipays://platformapi/startapp?saId=60000002";
/**
* 蚂蚁庄园
*/
private static final String ALI_MANOR_URL_SCHEME = "alipays://platformapi/startapp?appId=66666674";
/**
* 阿里运动
*/
private static final String ALI_SPORT_URL_SCHEME = "alipays://platformapi/startapp?saId=20000869";
/**
* QQ打卡
*/
private static final String QQ_CHECK_IN_URL_PREFIX = "aHR0cHM6Ly90aS5xcS5jb20vc2lnbmluL3B1YmxpYy9pbmRleC5odG1sP193dj0xMDkwNTMyMjU3Jl93d3Y9MTM=";
/**
* QQ早起奖金
*/
private static final String QQ_GET_UP_EARLY_URL_PREFIX = "aHR0cHM6Ly95dW5kb25nLnFxLmNvbS9wYWdlL3NpZ24vaW5kZXg/X3d2PTE4OTUwMTE1Jl93d3Y9MSZBRFRBRz1yZWRwa2cuYm9udXMucHVuY2hjYXJkJnN0ZXA9ODk1Mg==";
/**
* 微博早起奖金
*/
private static final String WEIBO_GET_UP_EARLY_URL = "https://getup.sc.weibo.com/home";
/**
* 支付宝早起打卡挑战赛
*/
private static final String ALI_SPORTS_GETUP_SERVER_URL_SCHEME = "alipays://platformapi/startapp?appId=20000067&url=https%3a%2f%2factivity-alisports.taobao.com%2fgetup";
/**
* 支付宝天天红包赛
*/
private static final String ALI_DD_SPORTS_SERVER_URL_SCHEME = "alipays://platformapi/startapp?appId=20000067&url=https%3a%2f%2fhuodong.taobao.com%2fwow%2ftyact%2fact%2fddsports-home-alipay%3fgame_type%3d1";
/**
* Project GitHub Url
*/
Expand All @@ -72,6 +35,11 @@ protected void onCreate(Bundle savedInstanceState) {
supportActionBar.setElevation(0);
}
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimary));

LinearLayout linearLayout = findViewById(R.id.ll_root);
SharedPreferencesConfig config = new SharedPreferencesConfig(getSharedPreferences("app_config", MODE_PRIVATE));
ViewFactory viewFactory = new ViewFactory(config, this);
viewFactory.start(linearLayout);
}

@Override
Expand All @@ -84,98 +52,13 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.github_for_star) {
startUrlScheme(GITHUB_FOR_STAR);
new StrategyContext(this, UrlSchemeStrategy.getInstance()).open(GITHUB_FOR_STAR);
return true;
}
return super.onOptionsItemSelected(item);
}

public void onBtnClick(View view) {
try {
switch (view.getId()) {
case R.id.qq_check_in: {
startQqLink(QQ_CHECK_IN_URL_PREFIX);
break;
}
case R.id.qq_get_up_early: {
startQqLink(QQ_GET_UP_EARLY_URL_PREFIX);
break;
}
case R.id.weibo_get_up_early: {
openWeiBoBrowser(WEIBO_GET_UP_EARLY_URL);
break;
}
case R.id.ali_tree: {
startUrlScheme(ALI_TREE_URL_SCHEME);
break;
}
case R.id.ali_manor: {
startUrlScheme(ALI_MANOR_URL_SCHEME);
break;
}
case R.id.ali_sport: {
startUrlScheme(ALI_SPORT_URL_SCHEME);
break;
}
case R.id.ali_sport_server: {
startUrlScheme(ALI_SPORTS_GETUP_SERVER_URL_SCHEME);
break;
}
case R.id.ali_dd_server: {
startUrlScheme(ALI_DD_SPORTS_SERVER_URL_SCHEME);
break;
}
default:
Toast.makeText(this, "未知选项", Toast.LENGTH_LONG).show();
}
} catch (ActivityNotFoundException e) {
Log.d(TAG, "app not found");
Toast.makeText(this, "APP没有找到", Toast.LENGTH_LONG).show();
} catch (Exception e) {
String msg = "error detail: " + e.getMessage();
Log.e(TAG, msg);
new AlertDialog.Builder(this)
.setTitle("错误")
.setMessage(msg)
.show();
}
}

/**
* 启动urlScheme
*
* @param urlScheme urlScheme
*/
private void startUrlScheme(@NonNull String urlScheme) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlScheme)));
}

/**
* 使用QQ内置浏览器打开链接
*
* @param urlPrefix 网址(必须使用base64进行编码)
*/
private void startQqLink(@NonNull String urlPrefix) {
String uri = String.format(QQ_BROWSER_URL_TEMPLATE, urlPrefix);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}

/**
* 打开微博客户端内置浏览器
*
* @param url 要打开的网页地址
*/
@SuppressWarnings("SameParameterValue")
private void openWeiBoBrowser(@NonNull String url) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("sinaweibo://browser?url=" + url));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
startUrlScheme(WEIBO_GET_UP_EARLY_URL);
} else if (item.getItemId() == R.id.view_setting) {
startActivity(new Intent(this, ViewSettingActivity.class));
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/top/itning/getupearly/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package top.itning.getupearly.config;

import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;

import java.util.Map;

import top.itning.getupearly.constant.Api;
import top.itning.getupearly.constant.ViewItem;

/**
* 用户配置
*
* @author itning
* @date 2020/8/10 20:04
*/
public interface Config<T> {
/**
* 获取配置信息
*
* @return 映射
*/
@NonNull
@CheckResult
Map<ViewItem<T>, Boolean> getConfig();

/**
* 保存配置信息
*
* @param api API
* @param isShow 是否显示
* @param order 顺序
*/
void saveConfig(@NonNull Api api, boolean isShow, int order);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package top.itning.getupearly.config;

import android.content.SharedPreferences;

import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;

import java.util.HashMap;
import java.util.Map;

import top.itning.getupearly.constant.Api;
import top.itning.getupearly.constant.ApiBundle;
import top.itning.getupearly.constant.ViewItem;

/**
* SharedPreferences实现配置
*
* @author itning
* @date 2020/8/10 20:07
*/
public class SharedPreferencesConfig implements Config<Api> {

private static final String ORDER_PREFIX = "ORDER_";

private static final String IS_SHOW_PREFIX = "SHOW_";

@NonNull
private final SharedPreferences sharedPref;

public SharedPreferencesConfig(@NonNull SharedPreferences sharedPref) {
this.sharedPref = sharedPref;
}

@Override
@NonNull
@CheckResult
public Map<ViewItem<Api>, Boolean> getConfig() {
Map<ViewItem<Api>, Boolean> map = new HashMap<>();
for (Api api : Api.values()) {
map.put(new ApiBundle(api, sharedPref.getInt(getOrderKey(api.name()), Integer.MAX_VALUE)), sharedPref.getBoolean(getIsShowKey(api.name()), true));
}
return map;
}

@Override
public void saveConfig(@NonNull Api api, boolean isShow, int order) {
sharedPref
.edit()
.putBoolean(getIsShowKey(api.name()), isShow)
.putInt(getOrderKey(api.name()), order)
.apply();
}

public static String getOrderKey(String value) {
return ORDER_PREFIX + value;
}

public static String getIsShowKey(String value) {
return IS_SHOW_PREFIX + value;
}
}
Loading

0 comments on commit 5ef13d8

Please sign in to comment.