Skip to content

Commit

Permalink
Merge pull request #90 from Bai-Jie/mergeMasterToRelease
Browse files Browse the repository at this point in the history
Merge master to release
  • Loading branch information
Zhou-Peican committed Dec 5, 2015
2 parents 12b3d6c + 660ca92 commit 624a46c
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 26 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.1.1] - 2015-12-05
### Changed
- 微调界面

### Fixed
- 修复有时遇到空主页,不显示内容的问题
- 修复“仅在WLAN下,播放视频”设置失效的问题
- 避免视频详情页加载缩略图时,先闪过全黑图的问题
- 修复一些会导致应用崩溃的问题

## [1.1.0] - 2015-12-03
### Changed
- 主页中向上滑动时,隐藏工具栏
Expand All @@ -25,6 +35,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- 显示播放记录
- 搜索视频

[Unreleased]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.0...HEAD
[Unreleased]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.1...HEAD
[1.1.1]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/OptimalOrange/CoolTechnologies/compare/8fada1475dc7a2ff179e3809650233fc2820c0fc...v1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ public static enum State {
/** 审核中 */
IN_REVIEW,
/** 已屏蔽 */
BLOCKED;
BLOCKED,
/** 暂未在文档中发现此项,但会遇到 */
LIMITED;

@NonNull
public static State fromStringIgnoreCase(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import com.optimalorange.cooltechnologies.ui.fragment.SettingsFragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class SettingsActivity extends BaseActivity {

public static void start(Context context) {
context.startActivity(new Intent(context, SettingsActivity.class));
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -83,18 +88,7 @@ public void onClick(View v) {
final ImageLoader.ImageListener imageListener = ImageLoader.getImageListener(
mViews.thumbnail, 0, 0
);
final ImageLoader.ImageListener imageListenerWrapper = new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
imageListener.onResponse(response, isImmediate);
mViews.thumbnail.setBackgroundResource(R.color.black);
}
@Override
public void onErrorResponse(VolleyError error) {
imageListener.onErrorResponse(error);
}
};
mVolleySingleton.getImageLoader().get(video.thumbnail, imageListenerWrapper);
mVolleySingleton.getImageLoader().get(video.thumbnail, imageListener);
}
}

Expand All @@ -103,10 +97,23 @@ public void playVideo() {
throw new IllegalStateException("cannot play video before load it.");
}

// 保存播放历史
DBManager.getInstance(this).saveHistory(mVideo);
// 跳转到 SimpleWebViewActivity
SimpleWebViewActivity.start(this, mVideo.link);
switch (NetworkError.checkNetwork(this)) {
case NO_ERROR:
// 保存播放历史
DBManager.getInstance(this).saveHistory(mVideo);
// 跳转到 SimpleWebViewActivity
SimpleWebViewActivity.start(this, mVideo.link);
break;
case NO_WIFI_NETWORK:
new NoWifiNetworkDialogFragment()
.show(getSupportFragmentManager(), "no_wifi_network");
break;
case NO_NETWORK:
new NoNetworkDialogFragment().show(getSupportFragmentManager(), "no_network");
break;
default:
throw new UnsupportedOperationException("Unsupported NetworkError");
}
}

/**
Expand Down Expand Up @@ -212,9 +219,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (defaultSharedPreferences.hasLoggedIn()) {
String token = defaultSharedPreferences.retrieveString("access_token", "");
if (mHasBookmarked) {
mVolleySingleton.addToRequestQueue(buildDestroyFavoriteRequest(token));
sendDestroyFavoriteRequest(token);
} else {
mVolleySingleton.addToRequestQueue(buildCreateFavoriteRequest(token));
sendCreateFavoriteRequest(token);
}
} else {
System.err.println("Shouldn't be [email protected]_bookmark");
Expand All @@ -236,22 +243,49 @@ private VideoDetailRequest buildVideoDetailRequest(String videoId) {
.build();
}

private boolean checkVideo() {
if (mVideo != null) {
return true;
} else {
Snackbar
.make(
findViewById(R.id.video_detail_root_view),
R.string.did_not_load_video,
Snackbar.LENGTH_LONG
)
.show();
return false;
}
}

public void sendCreateFavoriteRequest(String token) {
if (checkVideo()) {
mVolleySingleton.addToRequestQueue(buildCreateFavoriteRequest(token, mVideo));
}
}

public void sendDestroyFavoriteRequest(String token) {
if (checkVideo()) {
mVolleySingleton.addToRequestQueue(buildDestroyFavoriteRequest(token, mVideo));
}
}

/** 创建添加收藏的请求 */
private CreateFavoriteRequest buildCreateFavoriteRequest(String token) {
private CreateFavoriteRequest buildCreateFavoriteRequest(String token, Video video) {
return new CreateFavoriteRequest.Builder()
.setClient_id(mYoukuClientId)
.setVideo_id(mVideo.id)
.setVideo_id(video.id)
.setAccess_token(token)
.setResponseListener(new OnResponseListener(this, RequestType.CREATE_FAVORITE))
.setErrorListener(new OnErrorResponseListener(this, RequestType.CREATE_FAVORITE))
.build();
}

/** 创建取消收藏的请求 */
private DestroyFavoriteRequest buildDestroyFavoriteRequest(String token) {
private DestroyFavoriteRequest buildDestroyFavoriteRequest(String token, Video video) {
return new DestroyFavoriteRequest.Builder()
.setClient_id(mYoukuClientId)
.setVideo_id(mVideo.id)
.setVideo_id(video.id)
.setAccess_token(token)
.setResponseListener(new OnResponseListener(this, RequestType.DESTROY_FAVORITE))
.setErrorListener(new OnErrorResponseListener(this, RequestType.DESTROY_FAVORITE))
Expand Down Expand Up @@ -374,6 +408,83 @@ private int getToastTextResId() {
}
}

private enum NetworkError {
NO_ERROR,
NO_NETWORK,
NO_WIFI_NETWORK;

public static NetworkError checkNetwork(Context context) {
NetworkChecker networkChecker = NetworkChecker.newInstance(context);
if (DefaultSharedPreferencesSingleton.getInstance(context).onlyPlayVideoWhenUseWlan()) {
if (networkChecker.isConnected()) {
return networkChecker.isWifiConnected() ? NO_ERROR : NO_WIFI_NETWORK;
} else {
return NO_NETWORK;
}
} else {
return networkChecker.isConnected() ? NO_ERROR : NO_NETWORK;
}
}
}

public static class NoNetworkDialogFragment extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder
.setTitle(R.string.no_network_title)
.setMessage(R.string.no_network_message)
.setPositiveButton(
R.string.action_settings, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
NetworkChecker.openWirelessSettings(getContext());
}
})
.setNegativeButton(
android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do nothing when click cancel
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}

public static class NoWifiNetworkDialogFragment extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder
.setTitle(R.string.no_wifi_network_title)
.setItems(R.array.no_wifi_network_buttons,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
NetworkChecker.openWirelessSettings(getContext());
break;
case 1:
SettingsActivity.start(getContext());
break;
case 2:
// do nothing when click cancel
break;
default:
throw new UnsupportedOperationException("unsupported");
}
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}


private static class ViewHolder {

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_show_video_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/video_detail_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.optimalorange.cooltechnologies.ui.ShowVideoDetailActivity"
Expand Down Expand Up @@ -33,6 +34,7 @@
android:id="@+id/app_bar_image"
app:layout_widthPercent="100%"
app:layout_aspectRatio="178%"
android:scaleType="fitXY"
/>
</android.support.percent.PercentFrameLayout>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_simple_list_comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:textColor="@color/primary"
android:textColor="@color/accent"
android:textSize="@dimen/text_size_caption_dense"
android:text="@string/more_comments"
/>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
<string name="favorite_new_loading">正在加载中,请稍后……</string>
<string name="history_no_history">还没有历史记录哦~~</string>

<!-- ShowVideoDetailActivity -->
<string name="no_network_title">无可用网络</string>
<string name="no_network_message">现在修改系统网络设置?</string>
<string name="no_wifi_network_title">无WLAN网络</string>
<string name="no_wifi_network_button1">修改系统网络设置</string>
<string name="no_wifi_network_button2">修改此应用的设置</string>
<string-array name="no_wifi_network_buttons">
<item>@string/no_wifi_network_button1</item>
<item>@string/no_wifi_network_button2</item>
<item>@android:string/cancel</item>
</string-array>
<string name="did_not_load_video">尚未加载视频</string>

<!-- SearchActivity -->
<string name="search">搜索</string>

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<item name="colorAccent">@color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight, and colorSwitchThumbNormal. -->

<item name="alertDialogTheme">@style/AppTheme.Dialog</item>
</style>

<!-- see http://stackoverflow.com/questions/29790070/upgraded-to-appcompat-v22-1-0-and-now-getting-illegalargumentexception-appcompa -->
Expand All @@ -33,4 +35,10 @@

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>

</resources>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
PROJECTS_GROUP=com.optimalorange.cooltechnologies
VERSION_NAME=1.1.0
VERSION_NAME=1.1.1

0 comments on commit 624a46c

Please sign in to comment.