= SliderActivityViewModel::class.java
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/java/mustafaozhan/github/com/androcat/base/BaseActivity.kt:
--------------------------------------------------------------------------------
1 | package mustafaozhan.github.com.androcat.base
2 |
3 | import android.app.AlertDialog
4 | import android.graphics.Typeface
5 | import android.os.Bundle
6 | import androidx.annotation.IdRes
7 | import androidx.annotation.LayoutRes
8 | import androidx.appcompat.app.AppCompatActivity
9 | import androidx.core.content.ContextCompat
10 | import androidx.fragment.app.FragmentManager
11 | import de.mateware.snacky.Snacky
12 | import mustafaozhan.github.com.androcat.R
13 |
14 | /**
15 | * Created by Mustafa Ozhan on 2018-07-22.
16 | */
17 | @Suppress("TooManyFunctions")
18 | abstract class BaseActivity : AppCompatActivity() {
19 |
20 | @LayoutRes
21 | protected abstract fun getLayoutResId(): Int?
22 |
23 | @IdRes
24 | open var containerId: Int = R.id.content
25 |
26 | override fun onCreate(savedInstanceState: Bundle?) {
27 | super.onCreate(savedInstanceState)
28 |
29 | getLayoutResId()?.let {
30 | setContentView(it)
31 | getDefaultFragment()?.let { defaultFragment ->
32 | replaceFragment(defaultFragment, false)
33 | }
34 | }
35 | }
36 |
37 | open fun getDefaultFragment(): BaseFragment? = null
38 |
39 | private fun addFragment(containerViewId: Int, fragment: BaseFragment) {
40 | val ft = supportFragmentManager.beginTransaction()
41 | ft.add(containerViewId, fragment, fragment.fragmentTag)
42 | ft.commit()
43 | }
44 |
45 | protected fun addFragment(fragment: BaseFragment) {
46 | addFragment(containerId, fragment)
47 | }
48 |
49 | fun replaceFragment(fragment: BaseFragment, withBackStack: Boolean) {
50 | if (withBackStack) {
51 | replaceFragmentWithBackStack(containerId, fragment)
52 | } else {
53 | replaceFragment(containerId, fragment)
54 | }
55 | }
56 |
57 | private fun replaceFragmentWithBackStack(containerViewId: Int, fragment: BaseFragment) {
58 | val ft = supportFragmentManager.beginTransaction()
59 | ft.setCustomAnimations(
60 | R.anim.enter_from_right,
61 | R.anim.exit_to_left,
62 | R.anim.enter_from_left,
63 | R.anim.exit_to_right
64 | )
65 | ft.replace(containerViewId, fragment, fragment.fragmentTag)
66 | ft.addToBackStack(null)
67 | ft.commit()
68 | }
69 |
70 | private fun replaceFragment(containerViewId: Int, fragment: BaseFragment) {
71 | val ft = supportFragmentManager.beginTransaction()
72 | if (supportFragmentManager.backStackEntryCount != 0) {
73 | ft.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right)
74 | }
75 | ft.replace(containerViewId, fragment, fragment.fragmentTag)
76 | ft.commit()
77 | }
78 |
79 | fun clearBackStack() {
80 | if (supportFragmentManager.backStackEntryCount > 0) {
81 | supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
82 | }
83 | }
84 |
85 | fun snacky(text: String, actionText: String = "", action: () -> Unit = {}) {
86 | Snacky.builder()
87 | .setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary))
88 | .setText(text)
89 | .setIcon(R.mipmap.ic_launcher)
90 | .setActivity(this)
91 | .setDuration(Snacky.LENGTH_SHORT)
92 | .setActionText(actionText.toUpperCase())
93 | .setActionTextColor(ContextCompat.getColor(this, R.color.blue_gray_50))
94 | .setActionTextTypefaceStyle(Typeface.BOLD)
95 | .setActionClickListener {
96 | action()
97 | }
98 | .build()
99 | .show()
100 | }
101 |
102 | fun showDialog(
103 | title: String,
104 | description: String,
105 | positiveButton: String,
106 | cancelable: Boolean = true,
107 | function: () -> Unit = {}
108 | ) {
109 | if (!isFinishing) {
110 | val builder = AlertDialog
111 | .Builder(this, R.style.AlertDialogCustom)
112 | .setIcon(R.mipmap.ic_launcher)
113 | .setTitle(title)
114 | .setMessage(description)
115 | .setPositiveButton(positiveButton) { _, _ ->
116 | function()
117 | }
118 | .setCancelable(cancelable)
119 |
120 | if (cancelable) {
121 | builder.setNegativeButton(getString(R.string.cancel), null)
122 | }
123 |
124 | builder.show()
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/PrivacyPolicy.md:
--------------------------------------------------------------------------------
1 | ## Privacy Policy
2 |
3 | Mustafa Ozhan built the AndroCat app as a Free app. This SERVICE is provided by Mustafa Ozhan at no cost and is intended for use as is.
4 |
5 | This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.
6 |
7 | If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.
8 |
9 | The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at AndroCat unless otherwise defined in this Privacy Policy.
10 |
11 | ## Information Collection and Use
12 |
13 | For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not collected by me in any way.
14 |
15 | The app does use third party services that may collect information used to identify you.
16 |
17 | Link to privacy policy of third party service providers used by the app
18 |
19 | * [Google Play Services](https://www.google.com/policies/privacy/)
20 | * [AdMob](https://support.google.com/admob/answer/6128543?hl=en)
21 | * [Firebase Analytics](https://firebase.google.com/policies/analytics)
22 | * [Fabric](https://fabric.io/privacy)
23 |
24 | ## Log Data
25 |
26 | I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.
27 |
28 | ## Cookies
29 |
30 | Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.
31 |
32 | This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.
33 |
34 | ## Service Providers
35 |
36 | I may employ third-party companies and individuals due to the following reasons:
37 |
38 | * To facilitate our Service;
39 | * To provide the Service on our behalf;
40 | * To perform Service-related services; or
41 | * To assist us in analyzing how our Service is used.
42 |
43 | I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.
44 |
45 | ## Security
46 |
47 | I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.
48 |
49 | ## Links to Other Sites
50 |
51 | This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
52 |
53 | ## Children’s Privacy
54 |
55 | These Services do not address anyone under the age of 13\. I do not knowingly collect personally identifiable information from children under 13\. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions.
56 |
57 | ## Changes to This Privacy Policy
58 |
59 | I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page.
60 |
61 | ## Contact Us
62 |
63 | If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me.
64 |
65 | This privacy policy page was created at [privacypolicytemplate.net](https://privacypolicytemplate.net) and modified/generated by [App Privacy Policy Generator](https://app-privacy-policy-generator.firebaseapp.com/)
66 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AndroCat is a GitHub client for Android phones like how you used to
2 | 
3 |

4 | 
5 | Important! The old version has been removed from the Google Play Store. Download the updated AndroCat from the store icon above to get the latest updates.
6 |
7 | ## Screenshots
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | ## Dependencies
18 | ```gradle
19 | dependencies {
20 | implementation fileTree(include: ['*.jar'], dir: 'libs')
21 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
22 | implementation 'com.google.android.material:material:1.0.0'
23 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
24 |
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'androidx.test:runner:1.2.0'
27 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
28 |
29 | // Dagger
30 | kapt "com.google.dagger:dagger-compiler:${rootProject.ext.daggerVersion}"
31 | implementation "com.google.dagger:dagger:${rootProject.ext.daggerVersion}"
32 |
33 | // Crashlytics
34 | implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
35 |
36 | // Fabric
37 | implementation('com.crashlytics.sdk.android:crashlytics:2.10.0@aar') {
38 | transitive = true
39 | }
40 |
41 | // Anko
42 | implementation 'org.jetbrains.anko:anko-commons:0.10.8'
43 |
44 | // Retrofit
45 | implementation "com.google.code.gson:gson:${gsonVersion}"
46 | implementation "com.squareup.retrofit2:retrofit:${rootProject.ext.retrofitVersion}"
47 | implementation "com.squareup.retrofit2:converter-gson:${rootProject.ext.retrofitVersion}"
48 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
49 |
50 | // Http client
51 | implementation "com.squareup.okhttp3:okhttp:${rootProject.ext.okHttpVersion}"
52 |
53 | // Rx
54 | implementation "io.reactivex.rxjava2:rxkotlin:2.2.0"
55 | implementation "com.jakewharton.rxbinding2:rxbinding-kotlin:${rootProject.ext.rxBindingVersion}"
56 |
57 | // LiveData
58 | implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
59 |
60 | // Ad
61 | implementation 'com.google.firebase:firebase-ads:18.2.0'
62 |
63 | // Firebase
64 | implementation 'com.google.firebase:firebase-core:17.2.0'
65 | implementation 'com.google.firebase:firebase-config:19.0.0'
66 |
67 | // Advanced WebView
68 | implementation 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'
69 |
70 | // Quick Action
71 | implementation 'com.github.mustafaozhan:quickaction:3.0.2'
72 |
73 | // Bottom Navigation
74 | implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
75 |
76 | // Snacky
77 | implementation 'com.github.matecode:Snacky:1.0.3'
78 |
79 | // Multidex
80 | implementation 'androidx.multidex:multidex:2.0.1'
81 |
82 | // Joda Time
83 | implementation 'net.danlew:android.joda:2.10.1.2'
84 |
85 | // Android Fillable Loader
86 | implementation 'com.github.jorgecastilloprz:fillableloaders:1.03@aar'
87 | }
88 | ```
89 |
90 | ### License
91 | Copyright 2018 Mustafa Ozhan
92 |
93 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
94 |
95 |
96 |
97 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
98 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/mustafaozhan/github/com/androcat/notification/model/Notification.kt:
--------------------------------------------------------------------------------
1 | package mustafaozhan.github.com.androcat.notification.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | class Notification {
6 | @SerializedName("id")
7 | var id: String? = null
8 | @SerializedName("repository")
9 | var repository: Repository? = null
10 | @SerializedName("subject")
11 | var subject: Subject? = null
12 | @SerializedName("reason")
13 | var reason: String? = null
14 | @SerializedName("unread")
15 | var unread: Boolean? = null
16 | @SerializedName("updated_at")
17 | var updatedAt: String? = null
18 | @SerializedName("last_read_at")
19 | var lastReadAt: String? = null
20 | @SerializedName("url")
21 | var url: String? = null
22 | }
23 |
24 | class Owner {
25 | @SerializedName("login")
26 | var login: String? = null
27 | @SerializedName("id")
28 | var id: Int? = null
29 | @SerializedName("node_id")
30 | var nodeId: String? = null
31 | @SerializedName("avatar_url")
32 | var avatarUrl: String? = null
33 | @SerializedName("gravatar_id")
34 | var gravatarId: String? = null
35 | @SerializedName("url")
36 | var url: String? = null
37 | @SerializedName("html_url")
38 | var htmlUrl: String? = null
39 | @SerializedName("followers_url")
40 | var followersUrl: String? = null
41 | @SerializedName("following_url")
42 | var followingUrl: String? = null
43 | @SerializedName("gists_url")
44 | var gistsUrl: String? = null
45 | @SerializedName("starred_url")
46 | var starredUrl: String? = null
47 | @SerializedName("subscriptions_url")
48 | var subscriptionsUrl: String? = null
49 | @SerializedName("organizations_url")
50 | var organizationsUrl: String? = null
51 | @SerializedName("repos_url")
52 | var reposUrl: String? = null
53 | @SerializedName("events_url")
54 | var eventsUrl: String? = null
55 | @SerializedName("received_events_url")
56 | var receivedEventsUrl: String? = null
57 | @SerializedName("type")
58 | var type: String? = null
59 | @SerializedName("site_admin")
60 | var siteAdmin: Boolean? = null
61 | }
62 |
63 | class Repository {
64 | @SerializedName("id")
65 | var id: Int? = null
66 | @SerializedName("node_id")
67 | var nodeId: String? = null
68 | @SerializedName("name")
69 | var name: String? = null
70 | @SerializedName("full_name")
71 | var fullName: String? = null
72 | @SerializedName("owner")
73 | var owner: Owner? = null
74 | @SerializedName("private")
75 | var private: Boolean? = null
76 | @SerializedName("html_url")
77 | var htmlUrl: String? = null
78 | @SerializedName("description")
79 | var description: String? = null
80 | @SerializedName("fork")
81 | var fork: Boolean? = null
82 | @SerializedName("url")
83 | var url: String? = null
84 | @SerializedName("archive_url")
85 | var archiveUrl: String? = null
86 | @SerializedName("assignees_url")
87 | var assigneesUrl: String? = null
88 | @SerializedName("blobs_url")
89 | var blobsUrl: String? = null
90 | @SerializedName("branches_url")
91 | var branchesUrl: String? = null
92 | @SerializedName("collaborators_url")
93 | var collaboratorsUrl: String? = null
94 | @SerializedName("comments_url")
95 | var commentsUrl: String? = null
96 | @SerializedName("commits_url")
97 | var commitsUrl: String? = null
98 | @SerializedName("compare_url")
99 | var compareUrl: String? = null
100 | @SerializedName("contents_url")
101 | var contentsUrl: String? = null
102 | @SerializedName("contributors_url")
103 | var contributorsUrl: String? = null
104 | @SerializedName("deployments_url")
105 | var deploymentsUrl: String? = null
106 | @SerializedName("downloads_url")
107 | var downloadsUrl: String? = null
108 | @SerializedName("events_url")
109 | var eventsUrl: String? = null
110 | @SerializedName("forks_url")
111 | var forksUrl: String? = null
112 | @SerializedName("git_commits_url")
113 | var gitCommitsUrl: String? = null
114 | @SerializedName("git_refs_url")
115 | var gitRefsUrl: String? = null
116 | @SerializedName("git_tags_url")
117 | var gitTagsUrl: String? = null
118 | @SerializedName("git_url")
119 | var gitUrl: String? = null
120 | @SerializedName("issue_comment_url")
121 | var issueCommentUrl: String? = null
122 | @SerializedName("issue_events_url")
123 | var issueEventsUrl: String? = null
124 | @SerializedName("issues_url")
125 | var issuesUrl: String? = null
126 | @SerializedName("keys_url")
127 | var keysUrl: String? = null
128 | @SerializedName("labels_url")
129 | var labelsUrl: String? = null
130 | @SerializedName("languages_url")
131 | var languagesUrl: String? = null
132 | @SerializedName("merges_url")
133 | var mergesUrl: String? = null
134 | @SerializedName("milestones_url")
135 | var milestonesUrl: String? = null
136 | @SerializedName("notifications_url")
137 | var notificationsUrl: String? = null
138 | @SerializedName("pulls_url")
139 | var pullsUrl: String? = null
140 | @SerializedName("releases_url")
141 | var releasesUrl: String? = null
142 | @SerializedName("ssh_url")
143 | var sshUrl: String? = null
144 | @SerializedName("stargazers_url")
145 | var stargazersUrl: String? = null
146 | @SerializedName("statuses_url")
147 | var statusesUrl: String? = null
148 | @SerializedName("subscribers_url")
149 | var subscribersUrl: String? = null
150 | @SerializedName("subscription_url")
151 | var subscriptionUrl: String? = null
152 | @SerializedName("tags_url")
153 | var tagsUrl: String? = null
154 | @SerializedName("teams_url")
155 | var teamsUrl: String? = null
156 | @SerializedName("trees_url")
157 | var treesUrl: String? = null
158 | }
159 |
160 | class Subject {
161 | @SerializedName("title")
162 | var title: String? = null
163 | @SerializedName("url")
164 | var url: String? = null
165 | @SerializedName("latest_comment_url")
166 | var latestCommentUrl: String? = null
167 | @SerializedName("type")
168 | var type: String? = null
169 | }
170 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/mustafaozhan/github/com/androcat/settings/SettingsFragment.kt:
--------------------------------------------------------------------------------
1 | package mustafaozhan.github.com.androcat.settings
2 |
3 | import android.app.AlertDialog
4 | import android.content.ActivityNotFoundException
5 | import android.content.Intent
6 | import android.graphics.Color
7 | import android.net.Uri
8 | import android.os.Bundle
9 | import android.text.InputType
10 | import android.view.View
11 | import android.widget.EditText
12 | import kotlinx.android.synthetic.main.fragment_settings.ad_view
13 | import kotlinx.android.synthetic.main.fragment_settings.layout_dark_mode
14 | import kotlinx.android.synthetic.main.fragment_settings.layout_feedback
15 | import kotlinx.android.synthetic.main.fragment_settings.layout_notifications
16 | import kotlinx.android.synthetic.main.fragment_settings.layout_on_github
17 | import kotlinx.android.synthetic.main.fragment_settings.layout_remove_ads
18 | import kotlinx.android.synthetic.main.fragment_settings.layout_report_issue
19 | import kotlinx.android.synthetic.main.fragment_settings.layout_support
20 | import kotlinx.android.synthetic.main.fragment_settings.layout_username
21 | import kotlinx.android.synthetic.main.fragment_settings.switch_dark_mode
22 | import kotlinx.android.synthetic.main.fragment_settings.switch_notifications
23 | import kotlinx.android.synthetic.main.fragment_settings.tv_username_output
24 | import mustafaozhan.github.com.androcat.R
25 | import mustafaozhan.github.com.androcat.base.BaseMvvmFragment
26 | import mustafaozhan.github.com.androcat.extensions.checkAd
27 | import mustafaozhan.github.com.androcat.main.fragment.MainFragment
28 | import mustafaozhan.github.com.androcat.notification.NotificationReceiver
29 |
30 | /**
31 | * Created by Mustafa Ozhan on 2018-07-22.
32 | */
33 | class SettingsFragment : BaseMvvmFragment() {
34 |
35 | companion object {
36 | fun newInstance(): SettingsFragment = SettingsFragment()
37 | }
38 |
39 | override fun getViewModelClass(): Class = SettingsFragmentViewModel::class.java
40 |
41 | override fun getLayoutResId(): Int = R.layout.fragment_settings
42 |
43 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
44 | super.onViewCreated(view, savedInstanceState)
45 | init()
46 | setListeners()
47 | }
48 |
49 | private fun setListeners() {
50 | switch_dark_mode.setOnCheckedChangeListener { _, isChecked ->
51 | viewModel.updateSettings(darkMode = isChecked)
52 | }
53 | layout_dark_mode.setOnClickListener {
54 | switch_dark_mode.isChecked = !switch_dark_mode.isChecked
55 | }
56 |
57 | switch_notifications.setOnCheckedChangeListener { view, isChecked ->
58 | if (isChecked) {
59 | showDialog(
60 | getString(R.string.dialog_notifications_title),
61 | getString(R.string.dialog_notifications_message),
62 | getString(R.string.dialog_notifications_positive_button)
63 | ) {
64 | openUrlInMain(R.string.url_github_authorize)
65 | }
66 | } else {
67 | NotificationReceiver().cancelNotificationReceiver(view.context)
68 | viewModel.updateSettings(isNotificationOn = isChecked)
69 | }
70 | }
71 | layout_notifications.setOnClickListener {
72 | switch_notifications.isChecked = !switch_notifications.isChecked
73 | }
74 | layout_remove_ads.setOnClickListener { showRewardedAdDialog() }
75 | layout_username.setOnClickListener { showUsernameDialog() }
76 | layout_support.setOnClickListener {
77 | val intent = Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_androcat)))
78 | getBaseActivity()?.packageManager?.let { packageManager ->
79 | intent.resolveActivity(packageManager)?.let {
80 | showDialog(
81 | getString(R.string.support_us),
82 | getString(R.string.rate_and_support),
83 | getString(R.string.rate)
84 | ) {
85 | startActivity(intent)
86 | }
87 | }
88 | }
89 | }
90 | layout_feedback.setOnClickListener { sendFeedBack() }
91 | layout_on_github.setOnClickListener { openUrlInMain(R.string.url_project_repository) }
92 | layout_report_issue.setOnClickListener { openUrlInMain(R.string.url_report_issue) }
93 | }
94 |
95 | private fun openUrlInMain(stringId: Int) =
96 | replaceFragment(MainFragment.newInstance(getString(stringId)), false)
97 |
98 | private fun init() {
99 | viewModel.getUserName()?.let {
100 | tv_username_output?.text = it
101 | } ?: run { tv_username_output?.text = getString(R.string.missUsername) }
102 |
103 | viewModel.getSettings().darkMode?.let {
104 | switch_dark_mode.isChecked = it
105 | }
106 | viewModel.getSettings().isNotificationOn?.let {
107 | switch_notifications.isChecked = it
108 | }
109 | }
110 |
111 | private fun showUsernameDialog() {
112 | val editText = EditText(context).apply {
113 | setTextColor(Color.WHITE)
114 | setText(viewModel.getUserName())
115 | setSelection(this.text.length)
116 | inputType = InputType.TYPE_CLASS_TEXT
117 | }
118 |
119 | AlertDialog
120 | .Builder(context)
121 | .setTitle(getString(R.string.username))
122 | .setView(editText)
123 | .setPositiveButton("SAVE") { _, _ ->
124 | viewModel.updateUserName(editText.text.toString())
125 | tv_username_output?.text = editText.text.toString()
126 | }
127 | .setNegativeButton("CANCEL") { _, _ -> }
128 | .show()
129 | }
130 |
131 | private fun sendFeedBack() {
132 | try {
133 | Intent(Intent.ACTION_SEND).apply {
134 | type = "text/email"
135 | putExtra(Intent.EXTRA_EMAIL, arrayOf("mr.mustafa.ozhan@gmail.com"))
136 | putExtra(Intent.EXTRA_SUBJECT, "Feedback for AndroCat")
137 | putExtra(Intent.EXTRA_TEXT, "Dear Developer," + "")
138 | startActivity(Intent.createChooser(this, "Send Feedback:"))
139 | }
140 | } catch (activityNotFoundException: ActivityNotFoundException) {
141 | logException(activityNotFoundException)
142 | snacky("You do not have any mail application.")
143 | }
144 | }
145 |
146 | override fun onResume() {
147 | ad_view.checkAd(R.string.banner_ad_id, viewModel.isRewardExpired())
148 | super.onResume()
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroCat
3 | loading
4 | Settings
5 | Username
6 | Please Enter Your GitHub Username
7 | News Feed
8 | Search
9 | Search in GitHub
10 | Pull Requests
11 | Profile
12 | Issues
13 | Explore
14 | Back
15 | Forward
16 | Find
17 | User
18 | Stars
19 | Show Profile
20 | Dark Mode
21 | Log in
22 | Log out
23 | Settings
24 | Notifications
25 | Support
26 | Feedback
27 | On GitHub
28 | Trends
29 | New Gist
30 | New Repository
31 | Repositories
32 | Gists
33 | App Settings
34 | User Settings
35 | Enter
36 | Cancel
37 | Update
38 | Report Issue
39 | Find in page
40 | Stacks
41 | Production
42 | Projects
43 |
44 |
45 | about:blank
46 | https://github.com/login
47 | https://github.com/logout
48 | https://github.com/search
49 | https://github.com/trending
50 | https://github.com/
51 | https://github.com/pulls
52 | https://github.com/issues
53 | https://github.com/new
54 | https://gist.github.com/
55 | https://github.com/settings/profile
56 | https://github.com/notifications
57 | https://github.com/session
58 |
59 | https://github.com/%s
60 | https://github.com/%s?tab=stars
61 | https://github.com/%s?tab=repositories
62 | https://github.com/%s?tab=projects
63 | https://gist.github.com/%s
64 |
65 |
66 | https://github.com/MobilCat/AndroCat
67 | https://play.google.com/store/apps/details?id=mustafaozhan.github.com.androcat
68 | https://github.com/MobilCat/AndroCat/issues
69 |
70 | https://github.com/login/oauth/access_token
71 | https://github.com/login/oauth/authorize?client_id=e86c71c4a09a596dc857&scope=notifications
72 | /?code=
73 |
74 |
75 | github
76 | gist
77 | stargazers
78 | https://play.google.com
79 | https://github.com/org
80 | new
81 |
82 |
83 | Problem with the Internet connection.
84 | Server is temporarily not available.
85 | An unexpected error occurred.
86 |
87 |
88 | Support us !
89 | Please rate and comment to the app at Google Play Store :)
90 | RATE
91 | App Update
92 | Looks like you have an older\nversion of the app.\nPlease update to get latest\nfeatures and best experience.
93 |
94 |
95 | NEXT
96 | GOT IT
97 | AndroCat
98 | A traditional GitHub user interface, like how you are used to ! \n \n
99 | Mobile friendly pages \n \nDesktop pages have bigger text \n \nFaster load time
100 | Dark Mode !
101 | To activate it please go to: Explore > Dark mode
102 | Bugs & Issues
103 | If you experienced any Bug or Issue
104 | Please navigate\n\nUser > App Settings > Report Issue\n\n Than create a GitHub Issue to AndroCat Project\n\n Or\n\nUser > App Settings > Feedback\n\n Than send a email to us
105 | Disable Ads
106 | If you want to disable Ads for 24 hours
107 | Please navigate\n\nUser > App Settings > Disable Ads\n\n After you watch a video app will be ad free for 24 hours!
108 |
109 |
110 | Remove Ads
111 | Would you like to watch a video to stop ads for 24 hours ?
112 | Watch
113 |
114 |
115 | Enable Notifications
116 | In order to enable notifications you need to authorize AndroCat. Do you want to continue ?
117 | Yes
118 |
119 | Authorization successful
120 | Authorization failed, try again later
121 | Try again
122 |
123 |
124 |
125 | M48.950 41.000 C 42.065 55.078,40.104 83.280,43.734 116.000 C 46.943 144.919,46.659 146.585,35.839 162.226 C 25.141 177.691,8.000 219.951,8.000 230.861 C 8.000 234.974,45.933 236.000,198.000 236.000 L 388.000 236.000 388.000 226.503 C 388.000 213.317,377.785 185.692,364.938 164.131 C 354.648 146.862,354.198 143.887,355.474 101.589 C 357.849 22.882,325.058 8.107,270.291 63.207 L 255.587 78.000 199.668 77.690 L 143.750 77.379 128.875 62.930 C 100.642 35.505,57.435 23.650,48.950 41.000 M134.000 172.000 C 134.000 178.246,131.416 182.388,126.988 183.241 C 119.070 184.766,113.921 175.188,117.560 165.704 C 121.375 155.763,134.000 160.597,134.000 172.000 M286.000 172.000 C 286.000 183.403,273.375 188.237,269.560 178.296 C 265.921 168.812,271.070 159.234,278.988 160.759 C 283.416 161.612,286.000 165.754,286.000 172.000 M8.000 264.428 C 8.000 294.014,52.310 344.431,93.815 362.071 L 119.429 372.958 104.063 392.397 C 84.434 417.230,74.620 446.684,74.274 481.807 L 74.000 509.613 90.000 518.741 C 110.544 530.461,115.325 530.297,120.111 517.709 C 125.525 503.468,136.889 506.672,142.518 524.026 C 146.479 536.239,149.136 538.314,164.081 540.865 C 187.308 544.830,188.000 543.882,188.000 508.091 C 188.000 473.342,190.180 464.000,198.287 464.000 C 207.827 464.000,212.000 478.603,212.000 511.982 L 212.000 544.490 231.000 541.735 C 254.291 538.359,256.000 537.426,256.000 528.091 C 256.000 507.229,273.654 499.261,278.357 518.000 C 281.420 530.203,284.605 530.357,307.250 519.395 L 325.027 510.789 322.998 474.395 C 320.760 434.226,310.364 408.119,287.155 384.380 C 280.498 377.571,277.257 372.000,279.954 372.000 C 306.547 372.000,361.835 327.803,378.008 293.616 C 395.426 256.798,412.570 260.000,198.000 260.000 C 61.753 260.000,8.000 261.253,8.000 264.428
126 |
127 |
--------------------------------------------------------------------------------
/app/src/main/java/mustafaozhan/github/com/androcat/main/activity/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package mustafaozhan.github.com.androcat.main.activity
2 |
3 | import android.content.Intent
4 | import android.net.Uri
5 | import android.os.Bundle
6 | import android.os.Handler
7 | import android.text.TextUtils
8 | import android.view.KeyEvent
9 | import androidx.annotation.NonNull
10 | import com.google.android.gms.ads.AdRequest
11 | import com.google.android.gms.ads.InterstitialAd
12 | import com.google.android.gms.ads.rewarded.RewardItem
13 | import com.google.android.gms.ads.rewarded.RewardedAd
14 | import com.google.android.gms.ads.rewarded.RewardedAdCallback
15 | import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
16 | import com.google.firebase.remoteconfig.FirebaseRemoteConfig
17 | import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
18 | import com.google.gson.Gson
19 | import com.google.gson.JsonSyntaxException
20 | import io.reactivex.Observable
21 | import io.reactivex.android.schedulers.AndroidSchedulers
22 | import io.reactivex.disposables.Disposable
23 | import kotlinx.android.synthetic.main.fragment_main.web_view
24 | import mustafaozhan.github.com.androcat.BuildConfig
25 | import mustafaozhan.github.com.androcat.R
26 | import mustafaozhan.github.com.androcat.base.BaseFragment
27 | import mustafaozhan.github.com.androcat.base.BaseMvvmActivity
28 | import mustafaozhan.github.com.androcat.main.fragment.MainFragment
29 | import mustafaozhan.github.com.androcat.model.RemoteConfig
30 | import java.util.concurrent.TimeUnit
31 |
32 | /**
33 | * Created by Mustafa Ozhan on 2018-07-22.
34 | */
35 | @Suppress("TooManyFunctions")
36 | class MainActivity : BaseMvvmActivity() {
37 |
38 | companion object {
39 | var uri: String? = null
40 | const val BACK_DELAY: Long = 2000
41 | const val CHECK_DURATION: Long = 6
42 | const val CHECK_INTERVAL: Long = 4200
43 | const val REMOTE_CONFIG = "remote_config"
44 | const val AD_INITIAL_DELAY: Long = 50
45 | const val AD_PERIOD: Long = 250
46 | }
47 |
48 | private lateinit var rewardedAd: RewardedAd
49 | private lateinit var adObservableInterval: Disposable
50 | private lateinit var mInterstitialAd: InterstitialAd
51 |
52 | private var doubleBackToExitPressedOnce = false
53 | private var adVisibility = false
54 |
55 | override fun getDefaultFragment(): BaseFragment = MainFragment.newInstance(uri)
56 |
57 | override fun getViewModelClass(): Class = MainActivityViewModel::class.java
58 |
59 | override fun getLayoutResId(): Int = R.layout.activity_main
60 |
61 | override fun onCreate(savedInstanceState: Bundle?) {
62 | super.onCreate(savedInstanceState)
63 |
64 | val data = this.intent.data
65 | if (data != null && data.isHierarchical) {
66 | uri = this.intent.dataString
67 | }
68 | loadRewardedAd()
69 | checkAppUpdate()
70 | prepareAd()
71 | }
72 |
73 | override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
74 | val f = supportFragmentManager.findFragmentById(containerId)
75 |
76 | return if (f is MainFragment) {
77 | if (keyCode == KeyEvent.KEYCODE_BACK && web_view.canGoBack()) {
78 | web_view.goBack()
79 | true
80 | } else {
81 | super.onKeyUp(keyCode, event)
82 | }
83 | } else {
84 | super.onKeyUp(keyCode, event)
85 | }
86 | }
87 |
88 | override fun onBackPressed() {
89 |
90 | val f = supportFragmentManager.findFragmentById(containerId)
91 | if (f is MainFragment) {
92 | if (doubleBackToExitPressedOnce) {
93 | super.onBackPressed()
94 | return
95 | }
96 | this.doubleBackToExitPressedOnce = true
97 | snacky("Please click BACK again to exit")
98 | Handler().postDelayed({ doubleBackToExitPressedOnce = false }, BACK_DELAY)
99 | } else {
100 | super.onBackPressed()
101 | }
102 | }
103 |
104 | private fun loadRewardedAd() {
105 | rewardedAd = RewardedAd(this, getString(R.string.rewarded_ad_unit_id))
106 | rewardedAd.loadAd(AdRequest.Builder().build(), object : RewardedAdLoadCallback() {
107 | override fun onRewardedAdLoaded() = Unit
108 | override fun onRewardedAdFailedToLoad(errorCode: Int) = Unit
109 | })
110 | }
111 |
112 | private fun ad() {
113 | adVisibility = true
114 | adObservableInterval = Observable.interval(AD_INITIAL_DELAY, AD_PERIOD, TimeUnit.SECONDS)
115 | .debounce(0, TimeUnit.SECONDS)
116 | .observeOn(AndroidSchedulers.mainThread())
117 | .doOnNext {
118 | if (mInterstitialAd.isLoaded && adVisibility && viewModel.isRewardExpired()) {
119 | mInterstitialAd.show()
120 | } else {
121 | prepareAd()
122 | }
123 | }.doOnError(::logException)
124 | .subscribe()
125 | }
126 |
127 | internal fun showRewardedAdDialog() {
128 | showDialog(
129 | getString(R.string.dialog_remove_ads_title),
130 | getString(R.string.dialog_remove_ads_message),
131 | getString(R.string.dialog_remove_ads_positive_button)
132 | ) {
133 | showRewardedAd()
134 | }
135 | }
136 |
137 | private fun showRewardedAd() {
138 | if (rewardedAd.isLoaded) {
139 | rewardedAd.show(this, object : RewardedAdCallback() {
140 | override fun onRewardedAdOpened() = Unit
141 | override fun onRewardedAdClosed() = loadRewardedAd()
142 | override fun onRewardedAdFailedToShow(errorCode: Int) = loadRewardedAd()
143 | override fun onUserEarnedReward(@NonNull reward: RewardItem) {
144 | viewModel.updateAdFreeActivation()
145 | val intent = intent
146 | finish()
147 | startActivity(intent)
148 | }
149 | })
150 | }
151 | }
152 |
153 | private fun prepareAd() {
154 | mInterstitialAd = InterstitialAd(this)
155 | mInterstitialAd.adUnitId = getString(R.string.interstitial_ad_id)
156 | mInterstitialAd.loadAd(AdRequest.Builder().build())
157 | }
158 |
159 | private fun checkAppUpdate() {
160 |
161 | val defaultMap = HashMap()
162 | defaultMap[REMOTE_CONFIG] = RemoteConfig(
163 | getString(R.string.remote_config_title),
164 | getString(R.string.remote_config_description),
165 | getString(R.string.url_androcat)
166 | )
167 |
168 | FirebaseRemoteConfig
169 | .getInstance().apply {
170 | setConfigSettingsAsync(
171 | FirebaseRemoteConfigSettings
172 | .Builder()
173 | .setMinimumFetchIntervalInSeconds(CHECK_INTERVAL)
174 | .build()
175 | )
176 | setDefaultsAsync(defaultMap)
177 | fetch(if (BuildConfig.DEBUG) 0 else TimeUnit.HOURS.toSeconds(CHECK_DURATION))
178 | .addOnCompleteListener { task ->
179 | if (task.isSuccessful) {
180 | activate()
181 | if (TextUtils.isEmpty(getString(REMOTE_CONFIG))) {
182 | defaultMap[REMOTE_CONFIG] as? String
183 | } else {
184 | getString(REMOTE_CONFIG)
185 | }?.let { showUpdateDialog(it) }
186 | }
187 | }
188 | }
189 | }
190 |
191 | private fun showUpdateDialog(remoteConfigStr: String) {
192 | try {
193 | Gson().fromJson(
194 | remoteConfigStr,
195 | RemoteConfig::class.java
196 | ).apply {
197 | val isCancelable = forceVersion <= BuildConfig.VERSION_CODE
198 |
199 | if (latestVersion > BuildConfig.VERSION_CODE) {
200 | showDialog(title, description, getString(R.string.update), isCancelable) {
201 | startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(updateUrl)))
202 | }
203 | }
204 | }
205 | } catch (e: JsonSyntaxException) {
206 | logException(e)
207 | }
208 | }
209 |
210 | override fun onPause() {
211 | super.onPause()
212 | adObservableInterval.dispose()
213 | adVisibility = false
214 | }
215 |
216 | override fun onResume() {
217 | super.onResume()
218 | ad()
219 | }
220 |
221 | public override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
222 | super.onActivityResult(requestCode, resultCode, intent)
223 | supportFragmentManager?.findFragmentByTag(MainFragment.TAG)?.let { mainFragment ->
224 | if (mainFragment.isVisible) {
225 | mainFragment.onActivityResult(requestCode, resultCode, intent)
226 | }
227 | }
228 | }
229 | }
230 |
--------------------------------------------------------------------------------
/app/src/main/java/mustafaozhan/github/com/androcat/main/fragment/BaseMainFragment.kt:
--------------------------------------------------------------------------------
1 | package mustafaozhan.github.com.androcat.main.fragment
2 |
3 | import android.Manifest
4 | import android.app.Activity
5 | import android.content.Intent
6 | import android.graphics.Bitmap
7 | import android.os.Bundle
8 | import android.view.View
9 | import androidx.core.app.ActivityCompat
10 | import com.github.jorgecastillo.FillableLoader
11 | import im.delight.android.webview.AdvancedWebView
12 | import kotlinx.android.synthetic.main.fragment_main.web_view
13 | import kotlinx.android.synthetic.main.layout_fillable_loader.fillable_loader
14 | import kotlinx.android.synthetic.main.layout_fillable_loader.fillable_loader_dark
15 | import mustafaozhan.github.com.androcat.R
16 | import mustafaozhan.github.com.androcat.base.BaseMvvmFragment
17 | import mustafaozhan.github.com.androcat.extensions.isValidUsername
18 | import mustafaozhan.github.com.androcat.extensions.remove
19 | import mustafaozhan.github.com.androcat.extensions.runScript
20 | import mustafaozhan.github.com.androcat.main.activity.MainActivity
21 | import mustafaozhan.github.com.androcat.settings.SettingsFragment
22 | import mustafaozhan.github.com.androcat.tools.AccessTokenUtil
23 | import mustafaozhan.github.com.androcat.tools.JsScrip
24 | import mustafaozhan.github.com.androcat.tools.TextSize
25 |
26 | @Suppress("TooManyFunctions")
27 | abstract class BaseMainFragment : BaseMvvmFragment(), AdvancedWebView.Listener {
28 |
29 | companion object {
30 | const val AUTHENTICATION_COUNTER = 3
31 | const val EXTERNAL_STORAGE_PERMISSION_CODE = 111
32 | }
33 |
34 | protected lateinit var baseUrl: String
35 | private var loginCount = 0
36 | private var logoutCount = 0
37 | protected var isAnimating = false
38 | protected var userName = ""
39 | protected var loader: FillableLoader? = null
40 |
41 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
42 | super.onViewCreated(view, savedInstanceState)
43 | context?.getString(R.string.androcat_svg_path)?.let { path ->
44 | fillable_loader.setSvgPath(path)
45 | fillable_loader_dark.setSvgPath(path)
46 | }
47 | }
48 |
49 | override fun onPageStarted(url: String, favicon: Bitmap?) {
50 | if (!isAnimating) loadingView(true)
51 |
52 | with(url) {
53 | when {
54 | equals(getString(R.string.url_session)) -> {
55 | web_view?.runScript(JsScrip.GET_USERNAME) {
56 | userName = it?.remove("\"").toString()
57 | }
58 | updateVariables(login = true, logout = false)
59 | }
60 | equals(getString(R.string.url_github)) ->
61 | updateVariables(login = true, logout = false)
62 | equals(getString(R.string.url_logout)) ->
63 | updateVariables(login = false, logout = true)
64 | contains(getString(R.string.query_param_code)) ->
65 | context?.let { AccessTokenUtil(it, this) }
66 | else -> updateVariables(login = false, logout = false)
67 | }
68 | }
69 | }
70 |
71 | @Suppress("ComplexMethod")
72 | override fun onPageFinished(url: String) {
73 | with(url) {
74 | when {
75 | equals(getString(R.string.url_logout)) ->
76 | updateVariables(login = false, logout = true, textSize = TextSize.SMALL)
77 | contains(getString(R.string.url_session)) or
78 | contains(getString(R.string.url_login)) -> {
79 | web_view?.runScript(JsScrip.GET_USERNAME) {
80 | userName = it?.remove("\"").toString()
81 | }
82 | updateVariables(login = true, logout = false, textSize = TextSize.SMALL)
83 | }
84 | contains(getString(R.string.str_gist)) or
85 | contains(getString(R.string.url_issues)) or
86 | contains(getString(R.string.url_pulls)) or
87 | contains(getString(R.string.url_notifications)) or
88 | contains(getString(R.string.url_new)) or
89 | contains(getString(R.string.url_settings)) ->
90 | updateVariables(login = false, logout = false, textSize = TextSize.LARGE)
91 | contains(getString(R.string.url_search)) or
92 | contains(getString(R.string.url_trending)) or
93 | contains(getString(R.string.str_organization)) or
94 | contains(getString(R.string.str_google_play)) or
95 | contains(getString(R.string.str_new)) or
96 | !contains(getString(R.string.str_github)) or
97 | equals(getString(R.string.url_github)) ->
98 | updateVariables(login = false, logout = false, textSize = TextSize.SMALL)
99 | contains(getString(R.string.url_blank)) ->
100 | updateVariables(login = false, logout = false)
101 | contains(getString(R.string.str_stargazers)) ->
102 | updateVariables(login = false, logout = false, textSize = TextSize.MEDIUM)
103 | contains(viewModel.getUserName().toString()) -> updateVariables(
104 | login = false,
105 | logout = false,
106 | textSize = if (contains(getString(R.string.str_gist))) TextSize.LARGE else TextSize.SMALL
107 | )
108 | else -> updateVariables(
109 | textSize = if (contains(getString(R.string.url_github))) TextSize.SMALL else TextSize.LARGE
110 | )
111 | }
112 |
113 | viewModel.getSettings().darkMode?.let {
114 | web_view?.runScript(JsScrip.getTheme(it)) {
115 | loadingView(false)
116 | }
117 | }
118 | }
119 | }
120 |
121 | override fun onResume() {
122 | super.onResume()
123 | web_view?.onResume()
124 | if (MainActivity.uri != null) {
125 | loadUrl(urlStr = MainActivity.uri)
126 | MainActivity.uri = null
127 | }
128 | }
129 |
130 | override fun onDestroy() {
131 | super.onDestroy()
132 | web_view?.onPause()
133 | }
134 |
135 | override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
136 | super.onActivityResult(requestCode, resultCode, intent)
137 | web_view?.onActivityResult(requestCode, resultCode, intent)
138 | }
139 |
140 | @Suppress("TooGenericExceptionCaught", "NestedBlockDepth")
141 | override fun onDownloadRequested(
142 | url: String?,
143 | suggestedFilename: String?,
144 | mimeType: String?,
145 | contentLength: Long,
146 | contentDisposition: String?,
147 | userAgent: String?
148 | ) {
149 | try {
150 | (getBaseActivity() as? Activity)?.let {
151 | if (!hasPermissions(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
152 | ActivityCompat.requestPermissions(
153 | it,
154 | arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
155 | EXTERNAL_STORAGE_PERMISSION_CODE
156 | )
157 | } else {
158 | if (!AdvancedWebView.handleDownload(context, url, suggestedFilename)) {
159 | snacky("Download unsuccessful, download manager has been disabled on device")
160 | }
161 | loadUrl()
162 | }
163 | }
164 | } catch (e: Exception) {
165 | logException(e)
166 | }
167 | }
168 |
169 | override fun onExternalPageRequest(url: String?) = Unit
170 |
171 | override fun onPageError(errorCode: Int, description: String?, failingUrl: String?) = loadUrl(R.string.url_blank)
172 |
173 | protected fun loadIfUserNameSet(urlId: Int, addUserName: Boolean = false) = viewModel.apply {
174 | when {
175 | isLoggedIn() == false -> loadUrl(R.string.url_login, true)
176 | getUserName().isValidUsername() ->
177 | loadUrl(urlStr = if (addUserName) getString(urlId, getUserName()) else getString(urlId))
178 | else -> snacky(getString(R.string.missUsername), getString(R.string.enter)) {
179 | replaceFragment(SettingsFragment.newInstance(), true)
180 | }
181 | }
182 | }
183 |
184 | protected fun loadUrl(urlId: Int? = null, updateBaseUrl: Boolean = false, urlStr: String? = null) {
185 | loadingView(true)
186 | urlStr?.let {
187 | web_view?.loadUrl(it)
188 | } ?: run {
189 | urlId?.let { id ->
190 | if (updateBaseUrl) baseUrl = getString(id)
191 | web_view?.loadUrl(getString(id))
192 | }
193 | }
194 | }
195 |
196 | @Suppress("ComplexMethod")
197 | protected fun updateVariables(
198 | login: Boolean? = null,
199 | logout: Boolean? = null,
200 | textSize: TextSize? = null
201 | ) {
202 | login?.let { if (it) loginCount++ else loginCount = 0 }
203 | logout?.let { if (it) logoutCount++ else logoutCount = 0 }
204 | textSize?.let { web_view?.settings?.textZoom = it.value }
205 | when {
206 | loginCount == AUTHENTICATION_COUNTER -> viewModel.authentication(true)
207 | logoutCount == AUTHENTICATION_COUNTER -> viewModel.authentication(false)
208 | }
209 | }
210 |
211 | override fun getViewModelClass(): Class = MainFragmentViewModel::class.java
212 |
213 | abstract override fun getLayoutResId(): Int
214 |
215 | protected abstract fun loadingView(show: Boolean)
216 | }
217 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2018 Mustafa Ozhan
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/app/src/main/java/mustafaozhan/github/com/androcat/main/fragment/MainFragment.kt:
--------------------------------------------------------------------------------
1 | package mustafaozhan.github.com.androcat.main.fragment
2 |
3 | import android.annotation.SuppressLint
4 | import android.graphics.Color
5 | import android.os.Bundle
6 | import android.view.View
7 | import com.google.android.material.bottomnavigation.LabelVisibilityMode
8 | import com.jakewharton.rxbinding2.widget.textChanges
9 | import io.reactivex.rxkotlin.addTo
10 | import kotlinx.android.synthetic.main.fragment_main.bottom_navigation_view
11 | import kotlinx.android.synthetic.main.fragment_main.fab_news_feed
12 | import kotlinx.android.synthetic.main.fragment_main.layout_fillable_loader
13 | import kotlinx.android.synthetic.main.fragment_main.layout_find_in_page
14 | import kotlinx.android.synthetic.main.fragment_main.layout_swipe_refresh
15 | import kotlinx.android.synthetic.main.fragment_main.web_view
16 | import kotlinx.android.synthetic.main.layout_fillable_loader.fillable_loader
17 | import kotlinx.android.synthetic.main.layout_fillable_loader.fillable_loader_dark
18 | import kotlinx.android.synthetic.main.layout_find_in_page.edit_text_search
19 | import kotlinx.android.synthetic.main.layout_find_in_page.view_dismiss
20 | import kotlinx.android.synthetic.main.layout_find_in_page.view_search_next
21 | import kotlinx.android.synthetic.main.layout_find_in_page.view_search_previous
22 | import me.piruin.quickaction.QuickAction
23 | import mustafaozhan.github.com.androcat.R
24 | import mustafaozhan.github.com.androcat.extensions.applyColorFilter
25 | import mustafaozhan.github.com.androcat.extensions.hideKeyboard
26 | import mustafaozhan.github.com.androcat.extensions.initExplorerActions
27 | import mustafaozhan.github.com.androcat.extensions.initFeedActions
28 | import mustafaozhan.github.com.androcat.extensions.initProductionActions
29 | import mustafaozhan.github.com.androcat.extensions.initProfileActions
30 | import mustafaozhan.github.com.androcat.extensions.initStackActions
31 | import mustafaozhan.github.com.androcat.extensions.runScript
32 | import mustafaozhan.github.com.androcat.extensions.setBGColor
33 | import mustafaozhan.github.com.androcat.extensions.setVisibleWithAnimation
34 | import mustafaozhan.github.com.androcat.extensions.showKeyboard
35 | import mustafaozhan.github.com.androcat.settings.SettingsFragment
36 | import mustafaozhan.github.com.androcat.tools.JsScrip
37 |
38 | /**
39 | * Created by Mustafa Ozhan on 2018-07-22.
40 | */
41 | @Suppress("MagicNumber", "TooManyFunctions")
42 | class MainFragment : BaseMainFragment() {
43 | companion object {
44 | private const val ARGS_OPEN_URL = "ARGS_OPEN_URL"
45 | var TAG: String = MainFragment::class.java.simpleName
46 | fun newInstance(url: String?) = MainFragment().apply {
47 | arguments = Bundle().apply {
48 | putString(ARGS_OPEN_URL, url)
49 | }
50 | }
51 |
52 | fun newInstance() = MainFragment()
53 | }
54 |
55 | private var fromSetting = false
56 | private var quickActionProfile: QuickAction? = null
57 | private lateinit var quickActionFeed: QuickAction
58 | private lateinit var quickActionExplore: QuickAction
59 | private lateinit var quickActionStack: QuickAction
60 | private lateinit var quickActionProduction: QuickAction
61 |
62 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
63 | super.onViewCreated(view, savedInstanceState)
64 | arguments?.apply {
65 | getString(ARGS_OPEN_URL)?.let {
66 | loadUrl(urlStr = it)
67 | fromSetting = true
68 | baseUrl = it
69 | clear()
70 | }
71 | }
72 | init()
73 | setDash()
74 | initWebView()
75 | setListeners()
76 | setActionListeners()
77 |
78 | viewModel
79 | .loginSubject
80 | .subscribe(::handleLoginAction, ::logException)
81 | .addTo(compositeDisposable)
82 | }
83 |
84 | private fun handleLoginAction(isLoggedIn: Boolean) {
85 | if (isLoggedIn) {
86 | viewModel.updateUser(userName, isLoggedIn)
87 | } else {
88 | loadUrl(R.string.url_login)
89 | viewModel.updateUser("", isLoggedIn, null)
90 | }
91 | quickActionProfile = setProfileActions(isLoggedIn)
92 | }
93 |
94 | private fun init() {
95 | context?.apply {
96 | quickActionFeed = initFeedActions()
97 | quickActionExplore = initExplorerActions()
98 | quickActionStack = initStackActions()
99 | quickActionProduction = initProductionActions()
100 | }
101 |
102 | edit_text_search.background.mutate().applyColorFilter(Color.WHITE)
103 | fab_news_feed.bringToFront()
104 |
105 | quickActionProfile = setProfileActions(viewModel.isLoggedIn() == true)
106 |
107 | viewModel.getSettings().darkMode?.let { darkMode(it) }
108 |
109 | loadUrl(urlStr = baseUrl)
110 | }
111 |
112 | @Suppress("ComplexMethod")
113 | private fun setProfileActions(isLoggedIn: Boolean): QuickAction? {
114 | if (!fromSetting) {
115 | baseUrl = getString(if (isLoggedIn) R.string.url_github else R.string.url_login)
116 | }
117 | return context?.initProfileActions(isLoggedIn)?.apply {
118 | setOnActionItemClickListener { item ->
119 | when (item.actionId) {
120 | 1 -> loadIfUserNameSet(R.string.url_user_profile, true)
121 | 2 -> loadUrl(R.string.url_login)
122 | 3 -> loadUrl(R.string.url_logout)
123 | 4 -> loadIfUserNameSet(R.string.url_settings)
124 | 5 -> replaceFragment(SettingsFragment.newInstance(), true)
125 | }
126 | }
127 | }
128 | }
129 |
130 | private fun setListeners() {
131 | fab_news_feed.setOnClickListener { loadUrl(urlStr = baseUrl) }
132 | fab_news_feed.setOnLongClickListener {
133 | quickActionFeed.show(it)
134 | true
135 | }
136 | web_view?.setListener(getBaseActivity(), this)
137 |
138 | layout_swipe_refresh.setOnRefreshListener {
139 | loadUrl(urlStr = web_view?.url)
140 | layout_swipe_refresh.isRefreshing = false
141 | }
142 |
143 | bottom_navigation_view.setOnNavigationItemSelectedListener { item ->
144 | when (item.itemId) {
145 | R.id.nv_explorer -> quickActionExplore.show(bottom_navigation_view.getIconAt(0))
146 | R.id.nv_stacks -> quickActionStack.show(bottom_navigation_view.getIconAt(1))
147 | R.id.nv_production -> quickActionProduction.show(bottom_navigation_view.getIconAt(3))
148 | R.id.nv_profile -> quickActionProfile?.show(bottom_navigation_view.getIconAt(4))
149 | }
150 | true
151 | }
152 |
153 | edit_text_search.textChanges()
154 | .subscribe { txt ->
155 | web_view?.findAllAsync(txt.toString())
156 | }.addTo(compositeDisposable)
157 |
158 | view_search_next.setOnClickListener {
159 | web_view?.findNext(true)
160 | it.hideKeyboard()
161 | }
162 | view_search_previous.setOnClickListener {
163 | web_view?.findNext(false)
164 | it.hideKeyboard()
165 | }
166 | view_dismiss.setOnClickListener {
167 | edit_text_search.setText("")
168 | layout_find_in_page.setVisibleWithAnimation(false)
169 | layout_find_in_page.hideKeyboard()
170 | }
171 | }
172 |
173 | @Suppress("ComplexMethod")
174 | private fun setActionListeners() {
175 | quickActionFeed.setOnActionItemClickListener { item ->
176 | when (item.actionId) {
177 | 1 -> web_view?.goBack()
178 | 2 -> web_view?.goForward()
179 | 3 -> {
180 | layout_find_in_page.setVisibleWithAnimation(true)
181 | edit_text_search.showKeyboard()
182 | }
183 | }
184 | }
185 | quickActionExplore.setOnActionItemClickListener { item ->
186 | when (item.actionId) {
187 | 1 -> viewModel.getSettings().darkMode?.let { darkMode(!it, true) }
188 | 2 -> showRewardedAdDialog()
189 | 3 -> loadUrl(R.string.url_search)
190 | 4 -> loadUrl(R.string.url_trending)
191 | }
192 | }
193 | quickActionStack.setOnActionItemClickListener { item ->
194 | when (item.actionId) {
195 | 1 -> loadIfUserNameSet(R.string.url_notifications)
196 | 2 -> loadIfUserNameSet(R.string.url_user_stars, true)
197 | 3 -> loadIfUserNameSet(R.string.url_user_repositories, true)
198 | 4 -> loadIfUserNameSet(R.string.url_user_gists, true)
199 | }
200 | }
201 | quickActionProduction.setOnActionItemClickListener { item ->
202 | when (item.actionId) {
203 | 1 -> loadIfUserNameSet(R.string.url_issues)
204 | 2 -> loadIfUserNameSet(R.string.url_pulls)
205 | 3 -> loadIfUserNameSet(R.string.url_user_projects, true)
206 | 4 -> loadIfUserNameSet(R.string.url_new)
207 | 5 -> loadIfUserNameSet(R.string.url_gist)
208 | }
209 | }
210 | }
211 |
212 | private fun setDash() = bottom_navigation_view.apply {
213 | inflateMenu(R.menu.bnvm_dash)
214 | labelVisibilityMode = LabelVisibilityMode.LABEL_VISIBILITY_LABELED
215 | enableAnimation(false)
216 | setTextSize(10.0f)
217 | setIconsMarginTop(12)
218 | setIconSize(30.0F, 30.0F)
219 | getBottomNavigationItemView(2).isClickable = false
220 |
221 | for (i in 0..itemCount) {
222 | getLargeLabelAt(i)?.setPadding(0, 0, 0, 0)
223 | getBottomNavigationItemView(i)?.background = null
224 | }
225 | }
226 |
227 | @SuppressLint("SetJavaScriptEnabled")
228 | private fun initWebView() = web_view?.apply {
229 | setBackgroundColor(Color.parseColor("#FFFFFF"))
230 | settings.apply {
231 | setDesktopMode(true)
232 | useWideViewPort = true
233 | loadWithOverviewMode = true
234 | javaScriptEnabled = true
235 | setSupportZoom(true)
236 | builtInZoomControls = true
237 | displayZoomControls = false
238 | domStorageEnabled = true
239 | databaseEnabled = true
240 | }
241 | }
242 |
243 | private fun darkMode(darkMode: Boolean, changeSettings: Boolean = false) {
244 | loader = if (darkMode) {
245 | context?.let { layout_fillable_loader?.setBGColor(it, R.color.colorPrimaryDark) }
246 | fillable_loader?.visibility = View.GONE
247 | fillable_loader_dark
248 | } else {
249 | context?.let { layout_fillable_loader?.setBGColor(it, R.color.white) }
250 | fillable_loader_dark?.visibility = View.GONE
251 | web_view?.reload()
252 | fillable_loader
253 | }
254 | web_view?.runScript(JsScrip.getTheme(darkMode))
255 | if (changeSettings) viewModel.updateSettings(darkMode = darkMode)
256 | }
257 |
258 | override fun loadingView(show: Boolean) {
259 | if (show and !isAnimating) {
260 | isAnimating = true
261 | layout_fillable_loader?.setVisibleWithAnimation(true)
262 | loader?.visibility = View.VISIBLE
263 | fillable_loader?.start()
264 | fillable_loader_dark?.start()
265 | } else {
266 | layout_fillable_loader?.setVisibleWithAnimation(false)
267 | fillable_loader?.visibility = View.GONE
268 | fillable_loader_dark?.visibility = View.GONE
269 | fillable_loader?.reset()
270 | fillable_loader_dark?.reset()
271 | isAnimating = false
272 | }
273 | }
274 |
275 | override fun getLayoutResId(): Int = R.layout.fragment_main
276 | }
277 |
--------------------------------------------------------------------------------