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

Commit

Permalink
Merge branch 'release/1.0.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Feb 25, 2016
2 parents b2f9e24 + 60a95ef commit f29fc0a
Show file tree
Hide file tree
Showing 34 changed files with 424 additions and 282 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
> PS:官方客户端
### [CNode Swift for iOS](https://github.com/klesh/cnodejs-swift) ![image](/art/ic_good_project.png) ###

> CNode.js app written in Swift for iOS
> [https://cnodejs.org/topic/5698c285e5c79df62a37a13b](https://cnodejs.org/topic/5698c285e5c79df62a37a13b)
> PS:基于Swift的原生iOS客户端,体验良好
### [Noder](https://github.com/soliury/noder-react-native) ![image](/art/ic_good_project.png) ###

> A new [cnodejs.org](http://cnodejs.org) mobile app powered by [React-Native](http://facebook.github.io/react-native/) and [Redux](https://github.com/gaearon/redux).
Expand All @@ -92,9 +100,9 @@
> [https://cnodejs.org/topic/565c4473d0bc14ae279399fe](https://cnodejs.org/topic/565c4473d0bc14ae279399fe)
### [CNode-android](https://github.com/iwhys/CNode-android) ![image](/art/ic_good_project.png) ###
### [CNode-android](https://github.com/iwhys/CNode-android) ###

> 这是为CNodejs社区(https://cnodejs.org/) 开发的原生Android版客户端。适用于Android4.0及以上。
> 这是为CNodejs社区(https://cnodejs.org) 开发的原生Android版客户端。适用于Android4.0及以上。
> [https://cnodejs.org/topic/552dbeede10460475e7f7554](https://cnodejs.org/topic/552dbeede10460475e7f7554)
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
minSdkVersion 9
targetSdkVersion 22
versionCode Integer.parseInt(time)
versionName "1.0.13"
versionName "1.0.14"

manifestPlaceholders = [
UMENG_CHANNEL: "CNodeJS",
Expand All @@ -44,18 +44,18 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:design:23.2.0'

compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.code.gson:gson:2.5'
compile 'joda-time:joda-time:2.9.1'
compile 'com.google.code.gson:gson:2.6.1'
compile 'joda-time:joda-time:2.9.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.6.0'
compile 'com.squareup.picasso:picasso:2.5.2'

compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile ('com.afollestad.material-dialogs:core:0.8.5.0@aar') { transitive = true }
compile ('com.github.afollestad.material-dialogs:core:0.8.5.5@aar') { transitive = true }
compile 'com.pnikosis:materialish-progress:1.7'
compile 'com.melnykov:floatingactionbutton:1.3.0'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.takwolf.cnode_material;
package org.cnodejs.android.md;

import android.app.Application;
import android.test.ApplicationTestCase;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:configChanges="orientation|keyboardHidden|screenSize" />

<activity
android:name="org.cnodejs.android.md.ui.activity.QrCodeActivity"
android:name="org.cnodejs.android.md.ui.activity.QRCodeActivity"
android:label="@string/open_qrcode"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ public final class ApiClient {

private ApiClient() {}

private static final String API_HOST = "https://cnodejs.org/api";

public static final ApiService service = new RestAdapter.Builder()
.setEndpoint(API_HOST)
.setEndpoint(ApiDefine.API_HOST)
.setConverter(new GsonConverter(GsonWrapper.gson))
.setRequestInterceptor(new ApiRequestInterceptor())
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/org/cnodejs/android/md/model/api/ApiDefine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cnodejs.android.md.model.api;

import android.os.Build;

import org.cnodejs.android.md.BuildConfig;

public final class ApiDefine {

private ApiDefine() {}

public static final String API_HOST = "https://cnodejs.org/api";

public static final String USER_AGENT = "CNodeMD/" + BuildConfig.VERSION_NAME + " (Android " + Build.VERSION.RELEASE + "; " + Build.MANUFACTURER + " - " + Build.MODEL + ")";
public static final String HTTP_ACCEPT = "application/json";

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package org.cnodejs.android.md.model.api;

import android.os.Build;

import org.cnodejs.android.md.BuildConfig;

import retrofit.RequestInterceptor;

public class ApiRequestInterceptor implements RequestInterceptor {

private static final String APPLICATION_JSON = "application/json";
private static final String USER_AGENT = "CNodeMD/" + BuildConfig.VERSION_NAME + " (Android " + Build.VERSION.RELEASE + "; " + Build.MANUFACTURER + " - " + Build.MODEL + ")";

@Override
public void intercept(RequestFacade request) {
request.addHeader("Accept", APPLICATION_JSON);
request.addHeader("User-Agent", USER_AGENT);
request.addHeader("User-Agent", ApiDefine.USER_AGENT);
request.addHeader("Accept", ApiDefine.HTTP_ACCEPT);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.cnodejs.android.md.model.entity;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;

import org.cnodejs.android.md.util.FormatUtils;
Expand Down Expand Up @@ -75,4 +77,8 @@ public void setHandleContent(String content) {
handleContent = content;
}

public boolean isEmptyContent() {
return TextUtils.isEmpty(getContent()) || TextUtils.equals(getContent(), "<div class=\"markdown-text\"></div>");
}

}
80 changes: 48 additions & 32 deletions app/src/main/java/org/cnodejs/android/md/storage/LoginShared.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.cnodejs.android.md.storage;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import org.cnodejs.android.md.model.entity.LoginInfo;
import org.cnodejs.android.md.model.entity.User;
import org.joda.time.DateTime;

public final class LoginShared {

Expand All @@ -18,60 +16,78 @@ private LoginShared() {}
private static final String KEY_ID = "id";
private static final String KEY_LOGIN_NAME = "login_name";
private static final String KEY_AVATAR_URL = "avatar_url";
private static final String KEY_GITHUB_USERNAME = "github_username";
private static final String KEY_CREATE_AT = "create_at";
private static final String KEY_SCORE = "score";

public static void login(Context context, String accessToken, @NonNull LoginInfo loginInfo) {
SharedWrapper.with(context, TAG).setString(KEY_ACCESS_TOKEN, accessToken);
SharedWrapper.with(context, TAG).setString(KEY_ID, loginInfo.getId());
SharedWrapper.with(context, TAG).setString(KEY_LOGIN_NAME, loginInfo.getLoginName());
SharedWrapper.with(context, TAG).setString(KEY_AVATAR_URL, loginInfo.getAvatarUrl());
private static String accessToken;
private static String id;
private static String loginName;
private static String avatarUrl;
private static Integer score;

public static void login(Context context, String accessToken, LoginInfo loginInfo) {
SharedWrapper sharedWrapper = SharedWrapper.with(context, TAG);
sharedWrapper.setString(KEY_ACCESS_TOKEN, accessToken);
sharedWrapper.setString(KEY_ID, loginInfo.getId());
sharedWrapper.setString(KEY_LOGIN_NAME, loginInfo.getLoginName());
sharedWrapper.setString(KEY_AVATAR_URL, loginInfo.getAvatarUrl());
LoginShared.accessToken = accessToken;
id = loginInfo.getId();
loginName = loginInfo.getLoginName();
avatarUrl = loginInfo.getAvatarUrl();
}

public static void update(Context context, @NonNull User user) {
SharedWrapper.with(context, TAG).setString(KEY_LOGIN_NAME, user.getLoginName());
SharedWrapper.with(context, TAG).setString(KEY_AVATAR_URL, user.getAvatarUrl());
SharedWrapper.with(context, TAG).setString(KEY_GITHUB_USERNAME, user.getGithubUsername());
SharedWrapper.with(context, TAG).setString(KEY_CREATE_AT, user.getCreateAt().toString());
SharedWrapper.with(context, TAG).setInt(KEY_SCORE, user.getScore());
public static void update(Context context, User user) {
SharedWrapper sharedWrapper = SharedWrapper.with(context, TAG);
sharedWrapper.setString(KEY_LOGIN_NAME, user.getLoginName());
sharedWrapper.setString(KEY_AVATAR_URL, user.getAvatarUrl());
sharedWrapper.setInt(KEY_SCORE, user.getScore());
loginName = user.getLoginName();
avatarUrl = user.getAvatarUrl();
score = user.getScore();
}

public static void logout(Context context) {
SharedWrapper.with(context, TAG).clear();
accessToken = null;
id = null;
loginName = null;
avatarUrl = null;
score = null;
}

public static String getAccessToken(Context context) {
return SharedWrapper.with(context, TAG).getString(KEY_ACCESS_TOKEN, "");
if (TextUtils.isEmpty(accessToken)) {
accessToken = SharedWrapper.with(context, TAG).getString(KEY_ACCESS_TOKEN, null);
}
return accessToken;
}

public static String getId(Context context) {
return SharedWrapper.with(context, TAG).getString(KEY_ID, null);
if (TextUtils.isEmpty(id)) {
id = SharedWrapper.with(context, TAG).getString(KEY_ID, null);
}
return id;
}

public static String getLoginName(Context context) {
return SharedWrapper.with(context, TAG).getString(KEY_LOGIN_NAME, null);
if (TextUtils.isEmpty(loginName)) {
loginName = SharedWrapper.with(context, TAG).getString(KEY_LOGIN_NAME, null);
}
return loginName;
}

public static String getAvatarUrl(Context context) {
return SharedWrapper.with(context, TAG).getString(KEY_AVATAR_URL, null);
}

public static String getGithubUsername(Context context) {
return SharedWrapper.with(context, TAG).getString(KEY_GITHUB_USERNAME, null);
}

public static DateTime getCreateAt(Context context) {
String time = SharedWrapper.with(context, TAG).getString(KEY_CREATE_AT, null);
if (TextUtils.isEmpty(time)) {
return null;
} else {
return new DateTime(time);
if (TextUtils.isEmpty(avatarUrl)) {
avatarUrl = SharedWrapper.with(context, TAG).getString(KEY_AVATAR_URL, null);
}
return avatarUrl;
}

public static int getScore(Context context) {
return SharedWrapper.with(context, TAG).getInt(KEY_SCORE, 0);
if (score == null) {
score = SharedWrapper.with(context, TAG).getInt(KEY_SCORE, 0);
}
return score;
}

}
24 changes: 12 additions & 12 deletions app/src/main/java/org/cnodejs/android/md/storage/TopicShared.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ public final class TopicShared {

private TopicShared() {}

private static final String TAG = "TopicShared"; // TODO 这里需要添加当前用户loginName,避免用户数据混淆
private static final String TAG = "TopicShared";

private static String getSharedName(Context context) {
return TAG + "@" + LoginShared.getId(context);
}

private static final String KEY_NEW_TOPIC_TAB_POSITION = "new_topic_tab_position";
private static final String KEY_NEW_TOPIC_TITLE = "new_topic_title";
private static final String KEY_NEW_TOPIC_CONTENT = "new_topic_content";

private static String getTag(Context context) {
return TAG + "@" + LoginShared.getLoginName(context);
}

public static void clear(Context context) {
SharedWrapper.with(context, getTag(context)).clear();
SharedWrapper.with(context, getSharedName(context)).clear();
}

public static int getNewTopicTabPosition(Context context) {
return SharedWrapper.with(context, getTag(context)).getInt(KEY_NEW_TOPIC_TAB_POSITION, 0);
return SharedWrapper.with(context, getSharedName(context)).getInt(KEY_NEW_TOPIC_TAB_POSITION, 0);
}

public static void setNewTopicTabPosition(Context context, int position) {
SharedWrapper.with(context, getTag(context)).setInt(KEY_NEW_TOPIC_TAB_POSITION, position);
SharedWrapper.with(context, getSharedName(context)).setInt(KEY_NEW_TOPIC_TAB_POSITION, position);
}

public static String getNewTopicTitle(Context context) {
return SharedWrapper.with(context, getTag(context)).getString(KEY_NEW_TOPIC_TITLE, null);
return SharedWrapper.with(context, getSharedName(context)).getString(KEY_NEW_TOPIC_TITLE, null);
}

public static void setNewTopicTitle(Context context, String title) {
SharedWrapper.with(context, getTag(context)).setString(KEY_NEW_TOPIC_TITLE, title);
SharedWrapper.with(context, getSharedName(context)).setString(KEY_NEW_TOPIC_TITLE, title);
}

public static String getNewTopicContent(Context context) {
return SharedWrapper.with(context, getTag(context)).getString(KEY_NEW_TOPIC_CONTENT, null);
return SharedWrapper.with(context, getSharedName(context)).getString(KEY_NEW_TOPIC_CONTENT, null);
}

public static void setNewTopicContent(Context context, String content) {
SharedWrapper.with(context, getTag(context)).setString(KEY_NEW_TOPIC_CONTENT, content);
SharedWrapper.with(context, getSharedName(context)).setString(KEY_NEW_TOPIC_CONTENT, content);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ protected void onBtnAboutAuthorClick() {
ShipUtils.openInBrowser(this, getString(R.string.about_author_content));
}

@OnClick(R.id.about_btn_open_in_app_store)
protected void onBtnOpenInAppStoreClick() {
ShipUtils.openInAppStore(AboutActivity.this);
}

@OnClick(R.id.about_btn_advice_feedback)
protected void onBtnAdviceFeedbackClick() {
ShipUtils.sendEmail(
Expand All @@ -71,24 +76,6 @@ protected void onBtnAdviceFeedbackClick() {
"设备信息:Android " + Build.VERSION.RELEASE + " - " + Build.MANUFACTURER + " - " + Build.MODEL + "\n(如果涉及隐私请手动删除这个内容)\n\n");
}

@OnClick(R.id.about_fab_open_in_app_store)
protected void onBtnOpenInAppStoreClick() {
new MaterialDialog.Builder(this)
.title(R.string.open_in_app_store)
.content(R.string.open_in_app_store_content)
.positiveText(R.string.go_to_app_store)
.negativeText(R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {

@Override
public void onPositive(MaterialDialog dialog) {
ShipUtils.openInAppStore(AboutActivity.this);
}

})
.show();
}

@OnClick(R.id.about_btn_open_source_license)
protected void onBtnOpenSourceLicenseClick() {
startActivity(new Intent(this, LicenseActivity.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public void failure(RetrofitError error) {

@OnClick(R.id.login_btn_qrcode)
protected void onBtnQrcodeClick() {
startActivityForResult(new Intent(this, QrCodeActivity.class), REQUEST_QRCODE);
startActivityForResult(new Intent(this, QRCodeActivity.class), REQUEST_QRCODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_QRCODE && resultCode == RESULT_OK) {
edtAccessToken.setText(data.getStringExtra(QrCodeActivity.EXTRA_QRCODE));
edtAccessToken.setText(data.getStringExtra(QRCodeActivity.EXTRA_QRCODE));
edtAccessToken.setSelection(edtAccessToken.length());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class NotificationActivity extends StatusBarActivity implements Toolbar.O
@Bind(R.id.notification_recycler_view)
protected RecyclerView recyclerView;

@Bind(R.id.notification_layout_no_data)
protected ViewGroup layoutNoData;
@Bind(R.id.notification_icon_no_data)
protected View iconNoData;

private NotificationAdapter adapter;
private List<Message> messageList = new ArrayList<>();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void failure(RetrofitError error) {

private void notifyDataSetChanged() {
adapter.notifyDataSetChanged();
layoutNoData.setVisibility(messageList.size() == 0 ? View.VISIBLE : View.GONE);
iconNoData.setVisibility(messageList.size() == 0 ? View.VISIBLE : View.GONE);
}

private void showAccessTokenErrorDialog() {
Expand Down
Loading

0 comments on commit f29fc0a

Please sign in to comment.