├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── scopes
│ └── scope_settings.xml
└── vcs.xml
├── NyaSama.iml
├── README.md
├── app
├── .gitignore
├── app.iml
├── assets
│ ├── 1.png
│ ├── 2.png
│ ├── 3.png
│ ├── 4.png
│ ├── 5.png
│ ├── BGM.ogg
│ ├── BIU.ogg
│ ├── Back01.png
│ ├── Back02.png
│ ├── Bullet.png
│ ├── Graze.ogg
│ ├── Nyasama.png
│ └── Player.png
├── build.gradle
├── libs
│ ├── armeabi-v7a
│ │ ├── libgdx-box2d.so
│ │ └── libgdx.so
│ ├── armeabi
│ │ ├── libgdx-box2d.so
│ │ └── libgdx.so
│ └── x86
│ │ ├── libgdx-box2d.so
│ │ └── libgdx.so
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── nyasama
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── nyasama
│ │ ├── ThisApp.java
│ │ ├── activity
│ │ ├── AboutActivity.java
│ │ ├── AttachmentViewer.java
│ │ ├── BaseThemedActivity.java
│ │ ├── FavListActivity.java
│ │ ├── LoginActivity.java
│ │ ├── MainActivity.java
│ │ ├── MessagesActivity.java
│ │ ├── NewPostActivity.java
│ │ ├── NoticeActivity.java
│ │ ├── PMListActivity.java
│ │ ├── PostListActivity.java
│ │ ├── SearchActivity.java
│ │ ├── SettingActivity.java
│ │ ├── SplashActivity.java
│ │ ├── ThreadListActivity.java
│ │ └── UserProfileActivity.java
│ │ ├── fragment
│ │ ├── CommonListFragment.java
│ │ ├── DiscuzComicListFragment.java
│ │ ├── DiscuzForumIndexFragment.java
│ │ ├── DiscuzThreadListFragment.java
│ │ ├── DiscuzTopListFragment.java
│ │ ├── NavigationDrawerFragment.java
│ │ └── SimpleLayoutFragment.java
│ │ ├── libgdx
│ │ └── AboutCore.java
│ │ └── util
│ │ ├── BitmapLruCache.java
│ │ ├── CallbackMatcher.java
│ │ ├── CommonListAdapter.java
│ │ ├── Discuz.java
│ │ ├── Helper.java
│ │ ├── HtmlImageGetter.java
│ │ ├── InMemoryCookieStore.java
│ │ ├── MultipartRequest.java
│ │ ├── PersistenceCookieStore.java
│ │ ├── PhotoViewPager.java
│ │ ├── SafeHtmlText.java
│ │ └── SimpleIndicator.java
│ └── res
│ ├── drawable-hdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_new.png
│ ├── ic_action_reply.png
│ ├── ic_action_save.png
│ ├── ic_action_search.png
│ ├── ic_action_send_now.png
│ ├── ic_drawer.png
│ ├── ic_drawer_dark.png
│ ├── ic_launcher.png
│ └── ic_menu_emoticons.png
│ ├── drawable-mdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_new.png
│ ├── ic_action_reply.png
│ ├── ic_action_save.png
│ ├── ic_action_search.png
│ ├── ic_action_send_now.png
│ ├── ic_drawer.png
│ ├── ic_drawer_dark.png
│ ├── ic_launcher.png
│ └── ic_menu_emoticons.png
│ ├── drawable-xhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_new.png
│ ├── ic_action_reply.png
│ ├── ic_action_save.png
│ ├── ic_action_search.png
│ ├── ic_action_send_now.png
│ ├── ic_drawer.png
│ ├── ic_drawer_dark.png
│ ├── ic_launcher.png
│ └── ic_menu_emoticons.png
│ ├── drawable-xxhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_new.png
│ ├── ic_action_reply.png
│ ├── ic_action_save.png
│ ├── ic_action_search.png
│ ├── ic_action_send_now.png
│ ├── ic_drawer.png
│ ├── ic_drawer_dark.png
│ ├── ic_launcher.png
│ └── ic_menu_emoticons.png
│ ├── drawable
│ ├── ab_icon.png
│ ├── default_board_icon.jpg
│ ├── dot_indicator.xml
│ ├── joessr.png
│ ├── splash_anim.xml
│ ├── splash_anim1.png
│ └── splash_anim2.png
│ ├── layout
│ ├── activity_attachment_viewer.xml
│ ├── activity_login.xml
│ ├── activity_main.xml
│ ├── activity_new_post.xml
│ ├── activity_simple_framelayout.xml
│ ├── activity_splash_screen.xml
│ ├── activity_thread_list.xml
│ ├── activity_user_profile.xml
│ ├── dialog_ban_post.xml
│ ├── dialog_bump_thread.xml
│ ├── dialog_delete_post.xml
│ ├── dialog_delete_thread.xml
│ ├── dialog_digest_thread.xml
│ ├── dialog_highlight_thread.xml
│ ├── dialog_move_thread.xml
│ ├── dialog_open_thread.xml
│ ├── dialog_stick_thread.xml
│ ├── dialog_warn_post.xml
│ ├── fragment_attachment_image.xml
│ ├── fragment_attachment_indicator.xml
│ ├── fragment_attachment_item.xml
│ ├── fragment_blank.xml
│ ├── fragment_fav_item.xml
│ ├── fragment_forum_cat_item.xml
│ ├── fragment_forum_item.xml
│ ├── fragment_main_home.xml
│ ├── fragment_navigation_drawer.xml
│ ├── fragment_new_poll.xml
│ ├── fragment_notice_item.xml
│ ├── fragment_pm_from_me.xml
│ ├── fragment_pm_from_others.xml
│ ├── fragment_pmlist_item.xml
│ ├── fragment_post_item.xml
│ ├── fragment_select_attachment_item.xml
│ ├── fragment_simple_grid.xml
│ ├── fragment_simple_list.xml
│ ├── fragment_simple_list_loading.xml
│ ├── fragment_smiley_item.xml
│ ├── fragment_spinner_item_2.xml
│ ├── fragment_thread_grid.xml
│ ├── fragment_thread_item.xml
│ ├── fragment_upload_process.xml
│ ├── include_dialog_moderate_expiration.xml
│ ├── include_dialog_moderate_reason.xml
│ ├── include_indicator_right.xml
│ ├── include_sep_horizontal.xml
│ └── include_sep_vertical.xml
│ ├── menu
│ ├── global.xml
│ ├── main.xml
│ ├── menu_fav_list.xml
│ ├── menu_login.xml
│ ├── menu_messages.xml
│ ├── menu_new_post.xml
│ ├── menu_notice.xml
│ ├── menu_pm_list.xml
│ ├── menu_post_item.xml
│ ├── menu_post_list.xml
│ ├── menu_search.xml
│ ├── menu_setting.xml
│ ├── menu_thread_list.xml
│ └── menu_user_profile.xml
│ ├── values-en
│ └── strings.xml
│ ├── values-ja
│ └── strings.xml
│ ├── values-w820dp
│ └── dimens.xml
│ ├── values
│ ├── dimens.xml
│ ├── login_question.xml
│ ├── preference_values.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ ├── preference.xml
│ └── searchable.xml
├── build.gradle
├── extra
└── app_icon.xcf
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | .log
8 | /release
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | NyaSama
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/NyaSama.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | NyaSama
2 | =======
3 |
4 | 这里是 [喵玉殿](http://bbs.nyasama.com/) Android 客户端的咪
5 |
6 | ## Features
7 | 与已经停止更新的 Discuz 客户端 掌上论坛 不同,
8 | 这个客户端基于原生界面重新实现了论坛客户端的基本功能。
9 | 结合后端修改过的 [DiscuzMobile](https://github.com/NSDN/DiscuzMobile) 插件,
10 | 提供的拓展功能还包括
11 |
12 | * 帖子点评,投票,编辑,搜索等
13 | * 用户提醒和消息通知
14 | * 发送表情,自定板块图标,浏览图片附件的大图模式
15 | * 论坛签到等插件的支持
16 | * 帖子的删除,移动,置顶等(管理员)
17 |
18 |
19 | ## Contributing
20 | 请阅读 wiki 上的 [路线图](https://github.com/NSDN/NyaSama/wiki/Plan) 和 [待办事项](https://github.com/NSDN/NyaSama/wiki/TODOs)
21 |
22 | ## Credits
23 | 这个项目使用了以下开源项目提供的功能
24 |
25 | * [PhotoView](https://github.com/chrisbanes/PhotoView)
26 | * [libGDX](https://github.com/libGDX/libGDX)
27 | * [AndroidStaggeredGrid](https://github.com/etsy/AndroidStaggeredGrid)
28 | * [holoaccent](https://github.com/negusoft/holoaccent)
29 | * [DiskLruCache](https://github.com/JakeWharton/DiskLruCache)
30 | * [ACRA](https://github.com/ACRA/acra)
31 |
32 | 这个项目使用了 [OpenJDK](http://openjdk.java.net/) 中的源代码
33 |
34 | ## License
35 | GPL v2
36 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/app/assets/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/1.png
--------------------------------------------------------------------------------
/app/assets/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/2.png
--------------------------------------------------------------------------------
/app/assets/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/3.png
--------------------------------------------------------------------------------
/app/assets/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/4.png
--------------------------------------------------------------------------------
/app/assets/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/5.png
--------------------------------------------------------------------------------
/app/assets/BGM.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/BGM.ogg
--------------------------------------------------------------------------------
/app/assets/BIU.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/BIU.ogg
--------------------------------------------------------------------------------
/app/assets/Back01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/Back01.png
--------------------------------------------------------------------------------
/app/assets/Back02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/Back02.png
--------------------------------------------------------------------------------
/app/assets/Bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/Bullet.png
--------------------------------------------------------------------------------
/app/assets/Graze.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/Graze.ogg
--------------------------------------------------------------------------------
/app/assets/Nyasama.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/Nyasama.png
--------------------------------------------------------------------------------
/app/assets/Player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/assets/Player.png
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 20
5 | buildToolsVersion '20.0.0'
6 | defaultConfig {
7 | applicationId 'com.nyasama'
8 | minSdkVersion 15
9 | targetSdkVersion 20
10 | versionCode 1
11 | versionName 'nightly-debug-no-update'
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | packagingOptions {
20 | exclude 'META-INF/DEPENDENCIES'
21 | exclude 'META-INF/NOTICE'
22 | exclude 'META-INF/LICENSE'
23 | exclude 'META-INF/LICENSE.txt'
24 | exclude 'META-INF/NOTICE.txt'
25 | }
26 | productFlavors {
27 | }
28 | sourceSets {
29 | main {
30 | assets.srcDirs = ['assets']
31 | }
32 | }
33 | }
34 |
35 | task copyAndroidNatives() {
36 | file("libs/armeabi/").mkdirs();
37 | file("libs/armeabi-v7a/").mkdirs();
38 | file("libs/x86/").mkdirs();
39 |
40 | configurations.natives.files.each { jar ->
41 | def outputDir = null
42 | if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
43 | if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
44 | if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
45 | if(outputDir != null) {
46 | copy {
47 | from zipTree(jar)
48 | into outputDir
49 | include "*.so"
50 | }
51 | }
52 | }
53 | }
54 |
55 | tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
56 | pkgTask.jniFolders = new HashSet()
57 | pkgTask.jniFolders.add(new File(projectDir, 'libs'))
58 | }
59 |
60 | dependencies {
61 | compile fileTree(include: ['*.jar'], dir: 'libs')
62 | compile 'com.android.support:support-v4:21.0.2'
63 | compile 'com.mcxiaoke.volley:library-aar:1.0.0'
64 | compile 'com.github.chrisbanes.photoview:library:1.2.3'
65 | // adding this dependency causes gradle problem
66 | // REF: http://stackoverflow.com/questions/20673888/duplicate-files-copied-android-studio-0-4-0
67 | compile 'org.apache.httpcomponents:httpmime:4.2.2'
68 | compile 'com.badlogicgames.gdx:gdx:1.5.0'
69 | compile "com.badlogicgames.gdx:gdx-backend-android:1.5.0"
70 | compile 'com.etsy.android.grid:library:1.0.5'
71 | compile 'com.negusoft.holoaccent:library:1.1'
72 | compile 'com.jakewharton:disklrucache:2.0.2'
73 | compile 'ch.acra:acra:4.6.2'
74 | }
75 |
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libgdx-box2d.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/libs/armeabi-v7a/libgdx-box2d.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libgdx.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/libs/armeabi-v7a/libgdx.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libgdx-box2d.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/libs/armeabi/libgdx-box2d.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libgdx.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/libs/armeabi/libgdx.so
--------------------------------------------------------------------------------
/app/libs/x86/libgdx-box2d.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/libs/x86/libgdx-box2d.so
--------------------------------------------------------------------------------
/app/libs/x86/libgdx.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NSDN/NyaSama/ab5b52d0b74c5a1a8c4b8c1b3901089f3373ec1f/app/libs/x86/libgdx.so
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Programs\adk\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/nyasama/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.nyasama;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
17 |
18 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
55 |
56 |
59 |
60 |
63 |
64 |
65 |
130 |
131 |
134 |
135 |
138 |
139 |
142 |
143 |
146 |
147 |
150 |
151 |
154 |
155 |
158 |
159 |
163 |
164 |
168 |
169 |
170 |
171 |
173 |
174 |
175 |
176 |
177 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/ThisApp.java:
--------------------------------------------------------------------------------
1 | package com.nyasama;
2 |
3 | import android.app.AlarmManager;
4 | import android.app.Application;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.content.pm.PackageManager;
10 | import android.content.res.Configuration;
11 | import android.preference.PreferenceManager;
12 | import android.webkit.WebView;
13 |
14 | import com.android.volley.Cache;
15 | import com.android.volley.Network;
16 | import com.android.volley.RequestQueue;
17 | import com.android.volley.toolbox.BasicNetwork;
18 | import com.android.volley.toolbox.DiskBasedCache;
19 | import com.android.volley.toolbox.HurlStack;
20 | import com.android.volley.toolbox.ImageLoader;
21 | import com.jakewharton.disklrucache.DiskLruCache;
22 | import com.nyasama.activity.SplashActivity;
23 | import com.nyasama.util.BitmapLruCache;
24 | import com.nyasama.util.Helper;
25 | import com.nyasama.util.PersistenceCookieStore;
26 |
27 | import org.acra.ACRA;
28 | import org.acra.ReportingInteractionMode;
29 | import org.acra.annotation.ReportsCrashes;
30 | import org.acra.sender.HttpSender;
31 |
32 | import java.io.File;
33 | import java.io.IOException;
34 | import java.net.CookieHandler;
35 | import java.net.CookieManager;
36 | import java.net.CookiePolicy;
37 | import java.net.HttpURLConnection;
38 | import java.net.URL;
39 | import java.util.Locale;
40 |
41 | /**
42 | * Created by oxyflour on 2014/11/15.
43 | *
44 | * application 类里表示了本程序需要的最基本的设定和工具
45 | *
46 | * Volley 是 google 开发的工具包,它提供了更加方便的从 URL 载入图片的方法
47 | * Volley 的函数文档:
48 | * http://afzaln.com/volley/
49 | *
50 | * Android developer 文档:
51 | * http://developer.android.com/training/volley/index.html
52 | *
53 | * 不过这里的调用方法和 Android developer 文档中的方法不大一样,直接参考 javadoc 比较好
54 | *
55 | * Volley 类:
56 | * requestQueue:是一个 HTML 请求队列,调用 start() 后,就会不断地把队列中的请求发到对应的 URL 去以获得数据
57 | * imageLoader: 后台线程,用来下载 URL 中的图片并装载到组件上(调用见 MainActivity 中的 Avatar)
58 | * volleyCache: 缓存 HTML response 的储存器,imageLoader 另有别的储存器
59 | *
60 | * webView 类:
61 | * webView: 网页浏览器,用于运行javascript代码,用例见util.Discuz
62 | * cookieStore: 存储 cookie,目前用处不明,用例见util.Discuz
63 | *
64 | */
65 | @ReportsCrashes(
66 | formUri = "https://nsdn.cloudant.com/acra-nyasama/_design/acra-storage/_update/report",
67 | reportType = HttpSender.Type.JSON,
68 | httpMethod = HttpSender.Method.PUT,
69 | formUriBasicAuthLogin="diatimakedlyredgaingires",
70 | formUriBasicAuthPassword="GHxhyFvXLUoHAqMVkgCLSboe",
71 | mode = ReportingInteractionMode.TOAST,
72 | resToastText = R.string.acra_reporting_error)
73 |
74 | public class ThisApp extends Application {
75 | public static SharedPreferences preferences;
76 | public static Context context;
77 | public static Cache volleyCache;
78 | public static RequestQueue requestQueue;
79 | public static ImageLoader imageLoader;
80 | public static PersistenceCookieStore cookieStore;
81 | public static WebView webView;
82 | public static DiskLruCache fileDiskCache;
83 |
84 | // 下面的两个函数从sharedpreference 中读取语言设置
85 | private static Locale getLocale(String language) {
86 | String[] values = context.getResources().getStringArray(R.array.language_preference);
87 | Locale[] locales = {
88 | Locale.getDefault(),
89 | Locale.SIMPLIFIED_CHINESE,
90 | Locale.ENGLISH
91 | };
92 | for (int i = 0; i < locales.length && i < values.length; i ++)
93 | if (values[i].equals(language)) return locales[i];
94 | return Locale.getDefault();
95 | }
96 |
97 | // REF: http://aleung.github.io/blog/2012/10/06/change-locale-in-android-application/
98 | private static void loadLocale(String language) {
99 | Configuration config = new Configuration();
100 | config.locale = getLocale(language);
101 | context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
102 | }
103 |
104 | public static String getVersion() {
105 | try {
106 | return context.getPackageManager()
107 | .getPackageInfo(context.getPackageName(), 0).versionName;
108 | }
109 | catch (PackageManager.NameNotFoundException e) {
110 | e.printStackTrace();
111 | return "";
112 | }
113 | }
114 |
115 | public static void onSharedPreferenceChanged(SharedPreferences pref, String s) {
116 | if (s.equals(context.getString(R.string.pref_key_language))) {
117 | loadLocale(pref.getString(s, ""));
118 | }
119 | else if (s.equals(context.getString(R.string.pref_key_web_cache_size))) {
120 | volleyCache = new DiskBasedCache(new File(context.getCacheDir(), "NyasamaVolleyCache"),
121 | 1024 * 1024 * Helper.toSafeInteger(pref.getString(s, ""), 32));
122 | }
123 | else if (s.equals("disk_cache")) {
124 | int size = Helper.toSafeInteger(pref.getString(s, ""), 256);
125 | try {
126 | if (size > 0)
127 | fileDiskCache = DiskLruCache.open(new File(context.getExternalCacheDir(), "file-cache"),
128 | 0, 1, 1024 * 1024 * size);
129 | }
130 | catch (IOException e) {
131 | Helper.toast(e.getMessage());
132 | System.exit(1);
133 | }
134 | }
135 | }
136 |
137 | @Override
138 | public void onCreate() {
139 | super.onCreate();
140 | context = getApplicationContext();
141 |
142 | ACRA.init(this);
143 |
144 | // load preferences
145 | preferences = PreferenceManager.getDefaultSharedPreferences(context);
146 | ThisApp.onSharedPreferenceChanged(preferences, getString(R.string.pref_key_language));
147 | ThisApp.onSharedPreferenceChanged(preferences, getString(R.string.pref_key_web_cache_size));
148 | ThisApp.onSharedPreferenceChanged(preferences, getString(R.string.pref_key_manga_cache_size));
149 |
150 | // REF: http://stackoverflow.com/questions/18786059/change-redirect-policy-of-volley-framework
151 | //创建 HTML 请求队列
152 | Network network = new BasicNetwork(new HurlStack() {
153 | @Override
154 | protected HttpURLConnection createConnection(URL url) throws IOException {
155 | HttpURLConnection connection = super.createConnection(url);
156 | if (url.getRef() != null && url.getRef().contains("#hurlstack:noredirect#"))
157 | connection.setInstanceFollowRedirects(false);
158 | return connection;
159 | }
160 | });
161 | requestQueue = new RequestQueue(volleyCache, network);
162 | requestQueue.start();
163 |
164 | //创建 imageLoader ,与请求队列绑定,并使用 BitmapLruCache 存储器 (见util)
165 | ImageLoader.ImageCache imgCache = new BitmapLruCache();
166 | imageLoader = new ImageLoader(requestQueue, imgCache);
167 | //初始化webView 和 cookieStore
168 | cookieStore = new PersistenceCookieStore(context);
169 | CookieHandler.setDefault(new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL));
170 |
171 | webView = new WebView(context);
172 | webView.getSettings().setJavaScriptEnabled(true);
173 | }
174 |
175 | /*
176 | restart 函数设定为全局函数,更改语言后调用(或出现内部错误调用)
177 | alarmmanager 在0.1秒后激发 pendingintent,pendingintent 是一种自带操作的intent
178 | 这里的操作是启动一个activity (getactivities)
179 | 启动哪个 activity 则是由 pendingintent 中的另一个intent决定,这里启动的activity 是 splashactivity
180 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
181 | 这3个flag 确保启动的 activity 是task中的第一个 activty
182 | exit 的参数并没有特殊含义
183 | */
184 | public static void restart() {
185 | // REF: http://stackoverflow.com/questions/6609414/howto-programatically-restart-android-app
186 | Intent intent = new Intent(context, SplashActivity.class);
187 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
188 | Intent[] intents = {intent};
189 | PendingIntent pendingIntent = PendingIntent.getActivities(ThisApp.context, 0,
190 | intents,
191 | PendingIntent.FLAG_ONE_SHOT);
192 | AlarmManager mgr = (AlarmManager) ThisApp.context.getSystemService(Context.ALARM_SERVICE);
193 | mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
194 | System.exit(2);
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/activity/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.nyasama.activity;
2 | import android.content.Intent;
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import com.badlogic.gdx.backends.android.AndroidApplication;
6 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
7 | import com.nyasama.libgdx.AboutCore;
8 | /**
9 | * Created by D.zzm on 2014.12.14.
10 | */
11 | public class AboutActivity extends AndroidApplication {
12 | @Override
13 | protected void onCreate (Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
16 | initialize(new AboutCore(), config);
17 | }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/activity/BaseThemedActivity.java:
--------------------------------------------------------------------------------
1 | package com.nyasama.activity;
2 |
3 | import android.content.Intent;
4 | import android.content.res.Resources;
5 | import android.os.Bundle;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.view.MenuItem;
8 |
9 | import com.negusoft.holoaccent.AccentHelper;
10 | import com.negusoft.holoaccent.AccentResources;
11 | import com.nyasama.R;
12 | import com.nyasama.ThisApp;
13 | import com.nyasama.util.Discuz;
14 |
15 | /**
16 | * Created by oxyflour on 2015/1/2.
17 | * REF: https://github.com/negusoft/holoaccent/blob/master/HoloAccentExample/src/com/negusoft/holoaccent/example/activity/AccentFragmentActivity.java
18 | */
19 | public class BaseThemedActivity extends FragmentActivity {
20 |
21 | private final AccentHelper mAccentHelper = new AccentHelper(getOverrideAccentColor(),
22 | getOverrideAccentColorDark(), getOverrideAccentColorActionBar(), new MyInitListener());
23 |
24 | @Override
25 | public Resources getResources() {
26 | return mAccentHelper.getResources(this, super.getResources());
27 | }
28 |
29 | /**
30 | * Override this method to set the accent color programmatically.
31 | * @return The color to override. If the color is equals to 0, the
32 | * accent color will be taken from the theme.
33 | */
34 | public int getOverrideAccentColor() {
35 | // Note: we have to use ThisApp context to get string, or it will fail
36 | return ThisApp.preferences.getInt(ThisApp.context.getString(R.string.pref_key_theme_color), 0x616F8B);
37 | }
38 |
39 | /**
40 | * Override this method to set the dark variant of the accent color programmatically.
41 | * @return The color to override. If the color is equals to 0, the dark version will be
42 | * taken from the theme. If it is specified in the theme either, it will be calculated
43 | * based on the accent color.
44 | */
45 | public int getOverrideAccentColorDark() {
46 | return 0;
47 | }
48 |
49 | /**
50 | * Override this method to set the action bar variant of the accent color programmatically.
51 | * @return The color to override. If the color is equals to 0, the action bar version will
52 | * be taken from the theme. If it is specified in the theme either, it will the same as the
53 | * accent color.
54 | */
55 | public int getOverrideAccentColorActionBar() {
56 | return 0;
57 | }
58 |
59 | /** Getter for the AccentHelper instance. */
60 | @SuppressWarnings("unused")
61 | public AccentHelper getAccentHelper() {
62 | return mAccentHelper;
63 | }
64 |
65 | /**
66 | * Override this function to modify the AccentResources instance. You can add your own logic
67 | * to the default HoloAccent behaviour.
68 | */
69 | @SuppressWarnings("unused")
70 | public void onInitAccentResources(AccentResources resources) {
71 | // To be overriden in child classes.
72 | }
73 |
74 | private class MyInitListener implements AccentHelper.OnInitListener {
75 | @Override
76 | public void onInitResources(AccentResources resources) {
77 | onInitAccentResources(resources);
78 | }
79 | }
80 |
81 | @Override
82 | protected void onCreate(Bundle savedInstanceState) {
83 | super.onCreate(savedInstanceState);
84 |
85 | setTheme(ThisApp.preferences.getBoolean(getString(R.string.pref_key_animation), false) ?
86 | R.style.AppThemeAni : R.style.AppTheme);
87 |
88 | if (getActionBar() != null)
89 | getActionBar().setIcon(getResources().getDrawable(R.drawable.ab_icon));
90 | }
91 |
92 | @Override
93 | public boolean onOptionsItemSelected(MenuItem item) {
94 | int id = item.getItemId();
95 | if (id == android.R.id.home) {
96 | finish();
97 | return true;
98 | }
99 | else if (id == R.id.action_settings) {
100 | startActivity(new Intent(this, SettingActivity.class));
101 | return true;
102 | }
103 | else if (id == R.id.action_my_profile) {
104 | if (Discuz.sHasLogined)
105 | startActivity(new Intent(this, UserProfileActivity.class));
106 | else startActivityForResult(new Intent(this, LoginActivity.class),
107 | LoginActivity.REQUEST_CODE_LOGIN);
108 | return true;
109 | }
110 | return super.onOptionsItemSelected(item);
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/activity/FavListActivity.java:
--------------------------------------------------------------------------------
1 | package com.nyasama.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.View;
8 |
9 | import com.android.volley.Response;
10 | import com.nyasama.R;
11 | import com.nyasama.util.CommonListAdapter;
12 | import com.nyasama.fragment.CommonListFragment;
13 | import com.nyasama.util.Discuz;
14 | import com.nyasama.util.Discuz.FavItem;
15 | import com.nyasama.util.Helper;
16 |
17 | import org.json.JSONArray;
18 | import org.json.JSONException;
19 | import org.json.JSONObject;
20 |
21 | import java.util.HashMap;
22 | import java.util.List;
23 |
24 | public class FavListActivity extends BaseThemedActivity
25 | implements CommonListFragment.OnListFragmentInteraction {
26 |
27 | final static int PAGE_SIZE_COUNT = 20;
28 | public static String TAG = "FavList";
29 |
30 | private CommonListFragment mListFragment;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_simple_framelayout);
36 | if (getActionBar() != null)
37 | getActionBar().setDisplayHomeAsUpEnabled(true);
38 |
39 | mListFragment = CommonListFragment.getNewFragment(
40 | FavItem.class,
41 | R.layout.fragment_simple_list,
42 | R.layout.fragment_fav_item,
43 | R.id.list);
44 |
45 | getSupportFragmentManager().beginTransaction()
46 | .replace(R.id.container, mListFragment).commit();
47 | }
48 |
49 |
50 | @Override
51 | public boolean onCreateOptionsMenu(Menu menu) {
52 | // Inflate the menu; this adds items to the action bar if it is present.
53 | getMenuInflater().inflate(R.menu.menu_fav_list, menu);
54 | return true;
55 | }
56 |
57 | @Override
58 | public CommonListAdapter getListViewAdaptor(CommonListFragment fragment) {
59 | return new CommonListAdapter() {
60 | @Override
61 | public void convertView(ViewHolder viewHolder, FavItem item) {
62 | viewHolder.setText(R.id.title, item.title);
63 | viewHolder.setText(R.id.date, item.dateline);
64 | }
65 | };
66 | }
67 |
68 | @Override
69 | public void onItemClick(CommonListFragment fragment, View view, int position, long id) {
70 | FavItem item = mListFragment.getData(position);
71 | if ("tid".equals(item.type)) {
72 | Intent intent = new Intent(this, PostListActivity.class);
73 | intent.putExtra("tid", item.dataId);
74 | intent.putExtra("title", item.title);
75 | startActivity(intent);
76 | }
77 | }
78 |
79 | @Override
80 | @SuppressWarnings("unchecked")
81 | public void onLoadingMore(CommonListFragment fragment, final List listData) {
82 | final int page = listData.size() / PAGE_SIZE_COUNT;
83 | Discuz.execute("myfavthread", new HashMap() {{
84 | put("page", page + 1);
85 | }}, null, new Response.Listener() {
86 | @Override
87 | public void onResponse(JSONObject data) {
88 | int total = -1;
89 | if (data.has(Discuz.VOLLEY_ERROR)) {
90 | Helper.toast(R.string.network_error_toast);
91 | } else {
92 | Helper.setListLength(listData, page * PAGE_SIZE_COUNT);
93 | try {
94 | JSONObject var = data.getJSONObject("Variables");
95 |
96 | JSONArray list = var.getJSONArray("list");
97 | for (int i = 0; i < list.length(); i++) {
98 | listData.add(new FavItem(list.getJSONObject(i)));
99 | }
100 |
101 | total = Helper.toSafeInteger(var.getString("count"), listData.size());
102 |
103 | } catch (JSONException e) {
104 | Log.e(TAG, "JsonError: Load PM Lists Failed (" + e.getMessage() + ")");
105 | Helper.toast(R.string.load_failed_toast);
106 | }
107 | }
108 | mListFragment.loadMoreDone(total);
109 | }
110 | });
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/activity/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.nyasama.activity;
2 |
3 | import android.content.SharedPreferences;
4 | import android.os.Bundle;
5 | import android.view.Gravity;
6 | import android.view.Menu;
7 | import android.view.View;
8 | import android.widget.AdapterView;
9 | import android.widget.ArrayAdapter;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 | import android.widget.Spinner;
13 |
14 | import com.android.volley.Response;
15 | import com.nyasama.R;
16 | import com.nyasama.util.Discuz;
17 | import com.nyasama.util.Helper;
18 |
19 | import org.json.JSONObject;
20 |
21 | public class LoginActivity extends BaseThemedActivity
22 | implements AdapterView.OnItemSelectedListener {
23 |
24 | public static final int REQUEST_CODE_LOGIN = 1;
25 |
26 | public void doLogin(View view) {
27 | final String username = mUsername.getText().toString();
28 | final String password = mPassword.getText().toString();
29 | final String answer = mAnswer.getText().toString();
30 | if (username.isEmpty() || password.isEmpty()) {
31 | Helper.toast(getString(R.string.login_empty_message), Gravity.TOP, 0, 0.2);
32 | return;
33 | }
34 |
35 | Discuz.login(username, password, mQuestionId, answer, new Response.Listener() {
36 | @Override
37 | public void onResponse(JSONObject data) {
38 | if (data.has(Discuz.VOLLEY_ERROR)) {
39 | Helper.toast(R.string.network_error_toast);
40 | }
41 | else {
42 | JSONObject message = data.optJSONObject("Message");
43 | JSONObject var = data.optJSONObject("Variables");
44 | if (message != null) {
45 | String messageval = message.optString("messageval");
46 | if ("login_succeed".equals(messageval) ||
47 | "location_login_succeed".equals(messageval)) {
48 | // return uid to parent activity
49 | if (var != null)
50 | setResult(Helper.toSafeInteger(var.optString("member_uid"), 0));
51 | finish();
52 | }
53 | else
54 | Helper.toast(message.optString("messagestr"), Gravity.TOP, 0, 0.2);
55 | }
56 |
57 | SharedPreferences.Editor editor = mPrefs.edit();
58 | editor.putString("username", username);
59 | editor.apply();
60 | }
61 | mButton.setEnabled(true);
62 | }
63 | });
64 | mButton.setEnabled(false);
65 | }
66 |
67 | private EditText mUsername;
68 | private EditText mPassword;
69 | private Button mButton;
70 | private Spinner mQuestion;
71 | private int mQuestionId = 0;
72 | private EditText mAnswer;
73 | private SharedPreferences mPrefs;
74 |
75 | @Override
76 | protected void onCreate(Bundle savedInstanceState) {
77 | super.onCreate(savedInstanceState);
78 | setContentView(R.layout.activity_login);
79 | if (getActionBar() != null)
80 | getActionBar().setDisplayHomeAsUpEnabled(true);
81 |
82 | mUsername = (EditText) findViewById(R.id.username);
83 | mPassword = (EditText) findViewById(R.id.password);
84 | mButton = (Button) findViewById(R.id.login_button);
85 | mQuestion = (Spinner) findViewById(R.id.question);
86 | mAnswer = (EditText) findViewById(R.id.answer);
87 |
88 | ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
89 | R.array.login_question, android.R.layout.simple_spinner_item);
90 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
91 | mQuestion.setAdapter(adapter);
92 | mQuestion.setOnItemSelectedListener(this);
93 |
94 | mPrefs = getSharedPreferences("login_info", MODE_PRIVATE);
95 | mUsername.setText(mPrefs.getString("username", ""));
96 | }
97 |
98 |
99 | @Override
100 | public boolean onCreateOptionsMenu(Menu menu) {
101 | // Inflate the menu; this adds items to the action bar if it is present.
102 | getMenuInflater().inflate(R.menu.menu_login, menu);
103 | return true;
104 | }
105 |
106 | @Override
107 | public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
108 | mQuestionId = i;
109 | Helper.updateVisibility(mAnswer, mQuestionId > 0);
110 | }
111 |
112 | @Override
113 | public void onNothingSelected(AdapterView> adapterView) {
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/activity/PMListActivity.java:
--------------------------------------------------------------------------------
1 | package com.nyasama.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.View;
8 |
9 | import com.android.volley.Response;
10 | import com.android.volley.toolbox.NetworkImageView;
11 | import com.nyasama.R;
12 | import com.nyasama.ThisApp;
13 | import com.nyasama.util.CommonListAdapter;
14 | import com.nyasama.fragment.CommonListFragment;
15 | import com.nyasama.util.Discuz;
16 | import com.nyasama.util.Discuz.PMList;
17 | import com.nyasama.util.Helper;
18 |
19 | import org.json.JSONArray;
20 | import org.json.JSONException;
21 | import org.json.JSONObject;
22 |
23 | import java.util.HashMap;
24 | import java.util.List;
25 |
26 | public class PMListActivity extends BaseThemedActivity
27 | implements CommonListFragment.OnListFragmentInteraction {
28 |
29 | public static int PAGE_SIZE_COUNT = 20;
30 | public static String TAG = "PMList";
31 |
32 | private CommonListFragment mListFragment;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_simple_framelayout);
38 | if (getActionBar() != null)
39 | getActionBar().setDisplayHomeAsUpEnabled(true);
40 |
41 | mListFragment = CommonListFragment.getNewFragment(
42 | PMList.class,
43 | R.layout.fragment_simple_list,
44 | R.layout.fragment_pmlist_item,
45 | R.id.list);
46 |
47 | getSupportFragmentManager().beginTransaction()
48 | .replace(R.id.container, mListFragment).commit();
49 |
50 | }
51 |
52 |
53 | @Override
54 | public boolean onCreateOptionsMenu(Menu menu) {
55 | // Inflate the menu; this adds items to the action bar if it is present.
56 | getMenuInflater().inflate(R.menu.menu_pm_list, menu);
57 | return true;
58 | }
59 |
60 | @Override
61 | public CommonListAdapter getListViewAdaptor(CommonListFragment fragment) {
62 | return new CommonListAdapter() {
63 | @Override
64 | public void convertView(ViewHolder viewHolder, PMList item) {
65 | int uid = item.fromUserId != Discuz.sUid ? item.fromUserId : item.toUserId;
66 | String username = item.fromUserId != Discuz.sUid ? item.fromUser : item.toUser;
67 |
68 | String avatar_url = Discuz.DISCUZ_URL +
69 | "uc_server/avatar.php?uid=" + uid + "&size=small";
70 | ((NetworkImageView) viewHolder.getView(R.id.avatar))
71 | .setImageUrl(avatar_url, ThisApp.imageLoader);
72 |
73 | viewHolder.setText(R.id.author, username + " (" + item.number + ")");
74 | viewHolder.setText(R.id.message, item.message);
75 | viewHolder.setText(R.id.date, item.lastdate);
76 | }
77 | };
78 | }
79 |
80 | @Override
81 | public void onItemClick(CommonListFragment fragment, View view, int position, long id) {
82 | Intent intent = new Intent(this, MessagesActivity.class);
83 | intent.putExtra("touid", ((PMList) fragment.getData(position)).toUserId);
84 | startActivity(intent);
85 | }
86 |
87 | @Override
88 | @SuppressWarnings("unchecked")
89 | public void onLoadingMore(CommonListFragment fragment, final List listData) {
90 | final int page = listData.size() / PAGE_SIZE_COUNT;
91 | Discuz.execute("mypm", new HashMap() {{
92 | put("page", page + 1);
93 | }}, null, new Response.Listener() {
94 | @Override
95 | public void onResponse(JSONObject data) {
96 | int total = -1;
97 | if (data.has(Discuz.VOLLEY_ERROR)) {
98 | Helper.toast(R.string.network_error_toast);
99 | }
100 | else {
101 | Helper.setListLength(listData, page * PAGE_SIZE_COUNT);
102 | try {
103 | JSONObject var = data.getJSONObject("Variables");
104 |
105 | JSONArray list = var.getJSONArray("list");
106 | for (int i = 0; i < list.length(); i ++) {
107 | listData.add(new PMList(list.getJSONObject(i)));
108 | }
109 |
110 | total = Helper.toSafeInteger(var.getString("count"), listData.size());
111 |
112 | } catch (JSONException e) {
113 | Log.e(TAG, "JsonError: Load PM Lists Failed (" + e.getMessage() + ")");
114 | Helper.toast(R.string.load_failed_toast);
115 | }
116 | }
117 | mListFragment.loadMoreDone(total);
118 | }
119 | });
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/nyasama/activity/SearchActivity.java:
--------------------------------------------------------------------------------
1 | package com.nyasama.activity;
2 |
3 | import android.app.SearchManager;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.text.Html;
7 | import android.view.Menu;
8 | import android.view.View;
9 | import android.widget.SearchView;
10 |
11 | import com.android.volley.Response;
12 | import com.negusoft.holoaccent.dialog.AccentAlertDialog;
13 | import com.nyasama.R;
14 | import com.nyasama.fragment.CommonListFragment;
15 | import com.nyasama.util.CommonListAdapter;
16 | import com.nyasama.util.Discuz;
17 | import com.nyasama.util.Helper;
18 | import com.nyasama.util.Discuz.Thread;
19 |
20 | import org.json.JSONObject;
21 |
22 | import java.util.HashMap;
23 | import java.util.Iterator;
24 | import java.util.List;
25 |
26 | public class SearchActivity extends BaseThemedActivity
27 | implements CommonListFragment.OnListFragmentInteraction