Skip to content

Commit eb112b1

Browse files
committed
Add channel support
1 parent 262274c commit eb112b1

File tree

9 files changed

+104
-20
lines changed

9 files changed

+104
-20
lines changed

app/build.gradle

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 24
5-
buildToolsVersion "23.0.3"
5+
buildToolsVersion "24.0.1"
66

77
defaultConfig {
88
applicationId "com.quinn.githubknife"
99
minSdkVersion 15
1010
targetSdkVersion 23
11-
versionCode 6
12-
versionName "1.1"
11+
versionCode 102
12+
versionName "2.0"
1313
}
1414
buildTypes {
1515
release {
@@ -18,6 +18,11 @@ android {
1818
}
1919
}
2020

21+
lintOptions{
22+
checkReleaseBuilds false
23+
abortOnError false
24+
}
25+
2126

2227
}
2328

app/src/main/java/com/quinn/githubknife/GithubApplication.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
1111
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
1212
import com.quinn.githubknife.model.APKVersion;
13+
import com.quinn.githubknife.utils.ChannelUtils;
1314
import com.quinn.httpknife.github.User;
1415
import com.tendcloud.tenddata.TCAgent;
1516

@@ -26,7 +27,7 @@ public class GithubApplication extends Application {
2627
* @// TODO: 9/6/16
2728
* 暂时默认100,后续打多渠道此处得动态获取
2829
*/
29-
private final static String TD_CHANNEL_ID = "100";
30+
private String channel = "100";
3031

3132
private User user;
3233

@@ -38,10 +39,11 @@ public void onCreate() {
3839
super.onCreate();
3940
instance = this;
4041
/**
41-
* 初始化Taking-data
42+
* 初始化Talking-data
4243
*/
4344
TCAgent.LOG_ON = false;
44-
TCAgent.init(this, TD_APP_ID, TD_CHANNEL_ID);
45+
channel = ChannelUtils.getChannel(this);
46+
TCAgent.init(this, TD_APP_ID, channel);
4547
TCAgent.setReportUncaughtExceptions(true);
4648
// Initialize ImageLoader with configuration.
4749
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(

app/src/main/java/com/quinn/githubknife/interactor/FindItemsInteractorImpl.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
public class FindItemsInteractorImpl implements FindItemsInteractor {
4545

46-
private final static String TAG = FindItemsInteractor.class.getSimpleName();
46+
private final static String TAG = "FindItemsInteractor";
4747
private final static int LOAD_MORE_FAIL = 3;
4848
private final static int LOAD_FIRST_FAIL = 2;
4949
private final static int LOAD_SUCCESS = 1;
@@ -501,6 +501,7 @@ public void call(Subscriber<? super List<TrendingRepo>> subscriber) {
501501
Log.i(TAG, "starsDetial = " + starsDetail);
502502
}
503503

504+
starsDetail = starsDetail.replace(",", "");
504505
//正则解析语言、Star数量
505506
Pattern patternLanguage = Pattern.compile("[A-Za-z|+]{1,}"); //头个单词就是语言类别
506507
Pattern patternStarNum = Pattern.compile("[0-9]{1,}"); //头个数字就是Star数量

app/src/main/java/com/quinn/githubknife/ui/activity/SettingActivity.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import android.os.Bundle;
66
import android.support.v7.widget.Toolbar;
77
import android.view.MenuItem;
8+
import android.view.View;
9+
import android.widget.Toast;
810

911
import com.quinn.githubknife.GithubApplication;
1012
import com.quinn.githubknife.R;
1113
import com.quinn.githubknife.ui.BaseActivity;
1214
import com.quinn.githubknife.ui.widget.SettingLabel;
15+
import com.quinn.githubknife.utils.ChannelUtils;
16+
import com.quinn.githubknife.utils.ToastUtils;
1317

1418
import butterknife.Bind;
1519
import butterknife.ButterKnife;
@@ -20,17 +24,13 @@
2024
*/
2125
public class SettingActivity extends BaseActivity {
2226

23-
2427
//feature branch
2528
@Bind(R.id.toolbar)
2629
Toolbar toolbar;
2730

28-
2931
@Bind(R.id.version)
3032
SettingLabel version;
3133

32-
33-
3434
public static void launch(Context context){
3535
Intent intent = new Intent(context,SettingActivity.class);
3636
context.startActivity(intent);
@@ -46,6 +46,14 @@ protected void onCreate(Bundle savedInstanceState) {
4646
getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
4747
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
4848
version.setValue(((GithubApplication) getApplication()).getAPKVersion().getVersionName());
49+
version.setOnLongClickListener(new View.OnLongClickListener() {
50+
@Override
51+
public boolean onLongClick(View view) {
52+
String channelName = ChannelUtils.getChannelName(getApplicationContext());
53+
ToastUtils.showMsg(getApplicationContext(), channelName, Toast.LENGTH_LONG);
54+
return true;
55+
}
56+
});
4957
}
5058

5159

@@ -70,12 +78,6 @@ void author(){
7078
@OnClick(R.id.repo)
7179
void repo(){
7280

73-
74-
7581
}
7682

77-
78-
79-
80-
8183
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.quinn.githubknife.utils;
2+
3+
import android.content.Context;
4+
import android.content.pm.ApplicationInfo;
5+
import android.util.Log;
6+
7+
import java.io.IOException;
8+
import java.util.Enumeration;
9+
import java.util.HashMap;
10+
import java.util.zip.ZipEntry;
11+
import java.util.zip.ZipFile;
12+
13+
import static android.content.ContentValues.TAG;
14+
15+
/**
16+
* Created by Quinn on 25/10/2016.
17+
*/
18+
19+
public class ChannelUtils {
20+
21+
private static HashMap<String, String> channels = new HashMap<>();
22+
23+
static {
24+
channels.put("0", "dev_build");
25+
channels.put("1", "yingyongbao");
26+
channels.put("2", "google play");
27+
channels.put("3", "github");
28+
channels.put("4", "360");
29+
channels.put("5", "baidu");
30+
}
31+
32+
public static String getChannel(Context context) {
33+
ApplicationInfo appinfo = context.getApplicationInfo();
34+
String sourceDir = appinfo.sourceDir;
35+
String ret = "";
36+
ZipFile zipfile = null;
37+
try {
38+
zipfile = new ZipFile(sourceDir);
39+
Enumeration<?> entries = zipfile.entries();
40+
while (entries.hasMoreElements()) {
41+
ZipEntry entry = ((ZipEntry) entries.nextElement());
42+
String entryName = entry.getName();
43+
Log.i(TAG, "entryName = " + entryName);
44+
if (entryName.startsWith("channel") || entryName.startsWith("META-INF/channel")) {
45+
ret = entryName;
46+
break;
47+
}
48+
}
49+
} catch (IOException e) {
50+
e.printStackTrace();
51+
} finally {
52+
if (zipfile != null) {
53+
try {
54+
zipfile.close();
55+
} catch (IOException e) {
56+
e.printStackTrace();
57+
}
58+
}
59+
}
60+
61+
String[] split = ret.split("_");
62+
if (split != null && split.length >= 2) {
63+
return ret.substring(split[0].length() + 1);
64+
65+
} else {
66+
return "0";
67+
}
68+
}
69+
70+
public static String getChannelName(Context context) {
71+
return channels.get(getChannel(context));
72+
}
73+
74+
}

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010
}
1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:1.3.0'
12+
classpath 'com.android.tools.build:gradle:2.2.2'
1313

1414
// NOTE: Do not place your application dependencies here; they belong
1515
// in the individual module build.gradle files
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Jul 09 20:34:31 CST 2015
1+
#Sun Oct 09 23:32:35 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

screenshot/WeGit_v2.0.apk

3.76 MB
Binary file not shown.

screenshot/wegit_v0.7.apk

-2.58 MB
Binary file not shown.

0 commit comments

Comments
 (0)