Skip to content

Commit f577ae2

Browse files
committed
修正设置
1 parent d47b6f7 commit f577ae2

5 files changed

Lines changed: 174 additions & 13 deletions

File tree

diycode-app/src/main/java/com/gcssloop/diycode/activity/AboutActivity.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
package com.gcssloop.diycode.activity;
2424

2525
import android.content.Intent;
26-
import android.net.Uri;
2726
import android.view.View;
2827

2928
import com.gcssloop.diycode.R;
3029
import com.gcssloop.diycode.base.app.BaseActivity;
3130
import com.gcssloop.diycode.base.app.ViewHolder;
31+
import com.gcssloop.diycode.utils.IntentUtil;
3232

3333
public class AboutActivity extends BaseActivity implements View.OnClickListener {
34-
private String QRCode = "HTTPS://QR.ALIPAY.COM/FKX07101FYSJGTNCAPQW39";
3534

3635
@Override
3736
protected int getLayoutId() {
@@ -56,9 +55,7 @@ public void onClick(View v) {
5655
startActivity(intent);
5756
break;
5857
case R.id.contribute:
59-
Intent intent2 = new Intent(Intent.ACTION_VIEW);
60-
intent2.setData(Uri.parse("alipayqr://platformapi/startapp?saId=10000007&qrcode=" + QRCode));
61-
startActivity(intent2);
58+
IntentUtil.openAlipay(this);
6259
break;
6360
}
6461
}

diycode-app/src/main/java/com/gcssloop/diycode/activity/SettingActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
import com.gcssloop.diycode.R;
3030
import com.gcssloop.diycode.base.app.BaseActivity;
3131
import com.gcssloop.diycode.base.app.ViewHolder;
32+
import com.gcssloop.diycode.utils.AppUtil;
3233
import com.gcssloop.diycode.utils.Config;
3334
import com.gcssloop.diycode.utils.DataCleanManager;
3435
import com.gcssloop.diycode.utils.FileUtil;
36+
import com.gcssloop.diycode.utils.IntentUtil;
3537

3638
import java.io.File;
3739

@@ -59,13 +61,16 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
5961
}
6062
});
6163

64+
String versionName = AppUtil.getAppVersionName(this);
65+
holder.setText(R.id.app_version, versionName);
66+
6267
if (mDiycode.isLogin()) {
6368
holder.get(R.id.user).setVisibility(View.VISIBLE);
6469
} else {
6570
holder.get(R.id.user).setVisibility(View.GONE);
6671
}
6772

68-
holder.setOnClickListener(this, R.id.clear_cache, R.id.logout);
73+
holder.setOnClickListener(this, R.id.clear_cache, R.id.logout, R.id.about, R.id.contribute);
6974
}
7075

7176
// 显示缓存大小
@@ -95,6 +100,12 @@ public void onClick(View v) {
95100
showCacheSize(getViewHolder());
96101
toastShort("清除缓存成功");
97102
break;
103+
case R.id.about:
104+
openActivity(AboutActivity.class);
105+
break;
106+
case R.id.contribute:
107+
IntentUtil.openAlipay(this);
108+
break;
98109
}
99110
}
100111
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2017 GcsSloop
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Last modified 2017-03-29 05:11:04
17+
*
18+
* GitHub: https://github.com/GcsSloop
19+
* Website: http://www.gcssloop.com
20+
* Weibo: http://weibo.com/GcsSloop
21+
*/
22+
23+
package com.gcssloop.diycode.utils;
24+
25+
import android.content.Context;
26+
import android.content.pm.PackageInfo;
27+
import android.content.pm.PackageManager;
28+
import android.util.Log;
29+
30+
public class AppUtil {
31+
/**
32+
* 获取当前应用版本名称
33+
* @param context 上下文
34+
* @return 版本名
35+
*/
36+
public static String getAppVersionName(Context context) {
37+
String versionName = "";
38+
try {
39+
PackageManager pm = context.getPackageManager();
40+
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
41+
versionName = pi.versionName;
42+
int versioncode = pi.versionCode;
43+
if (versionName == null || versionName.length() <= 0) {
44+
return "";
45+
}
46+
} catch (Exception e) {
47+
Log.e("VersionInfo", "Exception", e);
48+
}
49+
return versionName;
50+
}
51+
52+
/**
53+
* 获取当前应用版本号
54+
* @param context 上下文
55+
* @return 版本号
56+
*/
57+
public static int getAppVersionCode(Context context) {
58+
int versioncode = 0;
59+
60+
try {
61+
PackageManager pm = context.getPackageManager();
62+
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
63+
versioncode = pi.versionCode;
64+
} catch (Exception e) {
65+
Log.e("VersionInfo", "Exception", e);
66+
}
67+
return versioncode;
68+
}
69+
}

diycode-app/src/main/java/com/gcssloop/diycode/utils/IntentUtil.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,31 @@
3030

3131
public class IntentUtil {
3232

33+
34+
/**
35+
* 打开链接
36+
* 根据设置判断是用那种方式打开
37+
*
38+
* @param context 上下文
39+
* @param url url
40+
*/
3341
public static void openUrl(Context context, String url) {
34-
// TODO 根据设置判断是使用内部,还是外部浏览器
3542
if (Config.getSingleInstance().isUseInsideBrowser()) {
3643
WebActivity.newInstance(context, url);
3744
} else {
3845
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
3946
context.startActivity(intent);
4047
}
4148
}
49+
50+
/**
51+
* 打开支付宝
52+
*/
53+
public static void openAlipay(Context context) {
54+
Intent intent = new Intent(Intent.ACTION_VIEW);
55+
String QRCode = "HTTPS://QR.ALIPAY.COM/FKX07101FYSJGTNCAPQW39";
56+
intent.setData(Uri.parse("alipayqr://platformapi/startapp?saId=10000007&qrcode=" + QRCode));
57+
context.startActivity(intent);
58+
}
59+
4260
}

diycode-app/src/main/res/layout/activity_setting.xml

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@
7777
</RelativeLayout>
7878

7979
<ImageView
80+
android:layout_width="match_parent"
81+
android:layout_height="1dp"
8082
android:background="@color/diy_white"
81-
android:src="@color/diy_gray"
8283
android:paddingLeft="16dp"
8384
android:paddingRight="16dp"
84-
android:layout_width="match_parent"
85-
android:layout_height="1dp"/>
85+
android:src="@color/diy_gray"/>
8686

8787
<RelativeLayout
8888
android:layout_width="match_parent"
@@ -97,15 +97,81 @@
9797
android:textSize="16sp"/>
9898

9999
<Switch
100-
android:textOn="内置"
101-
android:textOff="用户"
102100
android:id="@+id/use_inside_browser"
103101
android:layout_width="wrap_content"
104102
android:layout_height="wrap_content"
105103
android:layout_alignParentRight="true"
106-
android:checked="true"/>
104+
android:checked="true"
105+
android:textOff="用户"
106+
android:textOn="内置"/>
107+
</RelativeLayout>
108+
109+
<ImageView
110+
android:layout_width="match_parent"
111+
android:layout_height="1dp"
112+
android:background="@color/diy_white"
113+
android:paddingLeft="16dp"
114+
android:paddingRight="16dp"
115+
android:src="@color/diy_gray"/>
116+
117+
<RelativeLayout
118+
android:layout_width="match_parent"
119+
android:layout_height="wrap_content"
120+
android:background="@color/diy_white"
121+
android:padding="16dp">
122+
123+
<TextView
124+
android:layout_width="wrap_content"
125+
android:layout_height="wrap_content"
126+
android:text="当前版本"
127+
android:textSize="16sp"/>
128+
129+
<TextView
130+
android:id="@+id/app_version"
131+
android:layout_width="wrap_content"
132+
android:layout_height="wrap_content"
133+
android:layout_alignParentRight="true"
134+
android:checked="true"
135+
tools:text="v0.0.1"/>
107136
</RelativeLayout>
108137

138+
<ImageView
139+
android:layout_width="match_parent"
140+
android:layout_height="1dp"
141+
android:background="@color/diy_white"
142+
android:paddingLeft="16dp"
143+
android:paddingRight="16dp"
144+
android:src="@color/diy_gray"/>
145+
146+
147+
<TextView
148+
android:id="@+id/about"
149+
android:layout_width="match_parent"
150+
android:layout_height="wrap_content"
151+
android:background="@color/diy_white"
152+
android:padding="16dp"
153+
android:text="关于"
154+
android:textSize="16sp"/>
155+
156+
<ImageView
157+
android:layout_width="match_parent"
158+
android:layout_height="1dp"
159+
android:background="@color/diy_white"
160+
android:paddingLeft="16dp"
161+
android:paddingRight="16dp"
162+
android:src="@color/diy_gray"/>
163+
164+
<TextView
165+
android:id="@+id/contribute"
166+
android:layout_width="match_parent"
167+
android:layout_height="wrap_content"
168+
android:background="@color/diy_white"
169+
android:gravity="center"
170+
android:padding="16dp"
171+
android:text="¥ 捐赠一杯咖啡"
172+
android:textColor="#4AC432"
173+
android:textSize="16sp"/>
174+
109175
<LinearLayout
110176
android:id="@+id/user"
111177
android:layout_width="match_parent"

0 commit comments

Comments
 (0)