Skip to content

Commit

Permalink
[W.I.P] Rewrite app to MVP with Dependency Injection part 1 #22
Browse files Browse the repository at this point in the history
  • Loading branch information
xdk78 committed Feb 18, 2018
1 parent 53ad9a8 commit 616bf5d
Show file tree
Hide file tree
Showing 56 changed files with 619 additions and 2,518 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -14,9 +14,6 @@ cache:

env:
global:
- ANDROID_API=27
- EMULATOR_API=21
- ANDROID_BUILD_TOOLS=27.0.2
- secure: "Q69n6Io0RWFsXJvWjPPwkjXYftSKFSDSPVRwC/6nJuB4PquQ3MV2A5PuyAzWIgNXYMbOcNC/N5MNyPbm6MURot2U0yCYPg1L82ShVeEqSBpqTia+AZgzDh1ePeJY7BXtesnJ1c1XkumyhyLAf11m0YEyeP1/Lg26cdOhOavtK8nriis0a0Hycar7V1S/oG0s/7HKzFWv9eoNyD3dPm8WfJNoz2nYzykz+3sS8dec9nXJVj6eUu25rRKpePZ7J/jZqhsKSF8j4cecDe4ZHKKh3QjyNWy/TbtNyT4FnkJjTJky11mlq0//wt1JMU3kBjUjnrgs/iGMW3N1ANo36XhkuwMrECC9YvP0p+MmhHL8ApMzPOh091sEPzQLZgxo4Y5EI5flG8mPRNmmRK/3FfmYtyvOdbFT7d7JgPJksVgPggZ+5+iSfaTzRmxKPZLmnpamFe9HbbFPmaW6Q1ag72caX/IC2BmxwEjoHP261e3ruDVP2uTXWTKQAiI3FyVAhtaB3LiXUxF/pQGJ4Kq1ZjmvF28O5VZXIQMdIfg3Lj4zxEMCBuZpRfKebuhZe9lVj/lLIRMr0ahTLBA4r6ub3tPlfTfjrsxbIfTn8EqhLzDX7n0V2AC4vVj7iyUG5q8ma9tkZGgJcZGuZiG2jtGDkwmYQ37c4p5VJP7Ozy1yTtneCTQ="
- secure: "NwZUziNYooHs0wO9z+Nqw1UgF4XARVWZOV+PGxPp2LjqCkONFI38GWGS/JaeX/Rvf0p/TWBlyphaMBH5iTUem8EWR/AqvAtgNYy2H3BQJxhwgldTpDoQvBnv7j1B1jwd81Mif4s8SRBrfHm1nPKWidZQCJ/ASQVyaauiQonPRiYfc8qG3NeX6mKNke8mAwf84oF2Fv2WQD3asIqxH4b0L3icGSWwr5Gh7mRTjvyM78CdKDBggUNNKowP+9CXV/JAyKH+EHlKy5vsr+VWlFy1K4RX7RW7UqlHF69JM39lc+hNzua5j+OtwSYlEwBLc6xSBgu8Gnj2iHWg8rlZ5u4HdAPG2WnKlu39yU2t+xYXkAzgmI+pRgidNZi+D4TMdpSyKCsz7r0WjmwKRlzMzW+Gm+WA8Op2WJiOWW5aBYINPA157yLyTmkQgSkYh3UtonjMgsXavUC/ffCdaEEReypEccQaqjQORk7ol292KyYcQnTG0UaLK6m4jjcUFOrhcS/mW5TptnqEFDTl/hY3NBdgWyjrmj/gxK+CwXc/lwwn7zBv530KuXHgI8sAA6a7zJIIhidwT+PzvLkMKV5GQVhpsIArMdMawiZG6BU/SrEqn87Kb572+EIoIticV17dg/8Pv37j8gxkFKhUEK2UtQnKqbWHAI6vysEGjy8O1VZ7tfk="

Expand All @@ -30,7 +27,7 @@ before_install:
- ./gradlew dependencies || true

before_script:
- (while sleep 3; do echo "y"; done) | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" "extras;android;m2repository" "extras;google;m2repository" "build-tools;$ANDROID_BUILD_TOOLS" "platforms;android-$ANDROID_API"
- (while sleep 3; do echo "y"; done) | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" "extras;android;m2repository" "extras;google;m2repository" "build-tools;27.0.2" "platforms;android-27"

script:
- "./gradlew clean build connectedCheck -PdisablePreDex --stacktrace"
Expand Down
20 changes: 17 additions & 3 deletions app/build.gradle
Expand Up @@ -40,16 +40,30 @@ dependencies {
implementation "org.jetbrains.anko:anko:$anko_version"

// networking
implementation 'com.github.kittinunf.result:result:1.1.0'
implementation 'com.github.kittinunf.fuel:fuel-android:1.9.0'
implementation 'net.gotev:uploadservice:3.2.4'
implementation 'net.gotev:uploadservice-okhttp:3.2.4'
implementation "com.github.se-bastiaan:TorrentStream-Android:2.3.0"
implementation "com.github.se-bastiaan:TorrentStreamServer-Android:1.0.0"

// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

// rx
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.google.code.gson:gson:2.8.2'

// dagger 2
implementation "com.google.dagger:dagger:2.14.1"
kapt "com.google.dagger:dagger-compiler:2.14.1"
kapt "com.google.dagger:dagger-android-processor:2.14.1"
implementation "com.google.dagger:dagger-android:2.14.1"
implementation "com.google.dagger:dagger-android-support:2.14.1"

// image
implementation 'com.facebook.fresco:fresco:1.3.0'
implementation 'com.github.bumptech.glide:glide:4.6.1'
kapt 'com.github.bumptech.glide:compiler:4.6.1'

Expand Down
89 changes: 44 additions & 45 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -13,8 +13,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".application.Initializer"
android:allowBackup="true"
android:name=".MainApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand All @@ -35,57 +34,57 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_home"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ui.activity.TorrentActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<!--<activity-->
<!--android:name=".ui.activity.TorrentActivity"-->
<!--android:configChanges="keyboardHidden|orientation|screenSize">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.SEND" />-->

<category android:name="android.intent.category.DEFAULT" />
<!--<category android:name="android.intent.category.DEFAULT" />-->

<data android:mimeType="video/*" />
</intent-filter>
</activity>
<activity
android:name=".ui.activity.LoginActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_login" />
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<!--<data android:mimeType="video/*" />-->
<!--</intent-filter>-->
<!--</activity>-->
<!--<activity-->
<!--android:name=".ui.activity.LoginActivity"-->
<!--android:configChanges="keyboardHidden|orientation|screenSize"-->
<!--android:label="@string/title_activity_login" />-->
<!--<activity-->
<!--android:name="com.nononsenseapps.filepicker.FilePickerActivity"-->
<!--android:configChanges="keyboardHidden|orientation|screenSize"-->
<!--android:label="@string/app_name"-->
<!--android:theme="@style/FilePickerTheme">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.GET_CONTENT" />-->

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--</intent-filter>-->
<!--</activity>-->

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="cat.pantsu.nyaapantsu.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<!--<provider-->
<!--android:name="android.support.v4.content.FileProvider"-->
<!--android:authorities="cat.pantsu.nyaapantsu.provider"-->
<!--android:exported="false"-->
<!--android:grantUriPermissions="true">-->
<!--<meta-data-->
<!--android:name="android.support.FILE_PROVIDER_PATHS"-->
<!--android:resource="@xml/nnf_provider_paths" />-->
<!--</provider>-->

<activity
android:name=".ui.activity.SettingsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_settings"
android:theme="@style/AppTheme.NoActionBar">
<!--<activity-->
<!--android:name=".ui.activity.SettingsActivity"-->
<!--android:configChanges="keyboardHidden|orientation|screenSize"-->
<!--android:label="@string/title_activity_settings"-->
<!--android:theme="@style/AppTheme.NoActionBar">-->

</activity>
<!--</activity>-->

<activity
android:name=".ui.activity.ProfileActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_profile" >
<!--<activity-->
<!--android:name=".ui.activity.ProfileActivity"-->
<!--android:configChanges="keyboardHidden|orientation|screenSize"-->
<!--android:label="@string/title_activity_profile" >-->

</activity>
<!--</activity>-->
</application>

</manifest>
14 changes: 14 additions & 0 deletions app/src/main/java/cat/pantsu/nyaapantsu/MainApp.kt
@@ -0,0 +1,14 @@
package cat.pantsu.nyaapantsu


import cat.pantsu.nyaapantsu.di.component.DaggerMainComponent
import dagger.android.AndroidInjector
import dagger.android.support.DaggerApplication


class MainApp : DaggerApplication() {

override fun applicationInjector(): AndroidInjector<out DaggerApplication> =
DaggerMainComponent.builder().create(this)

}
Expand Up @@ -12,23 +12,21 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import cat.pantsu.nyaapantsu.R
import cat.pantsu.nyaapantsu.model.Torrent
import cat.pantsu.nyaapantsu.ui.activity.TorrentActivity
import cat.pantsu.nyaapantsu.mvp.model.TorrentListModel
import cat.pantsu.nyaapantsu.mvp.model.TorrentListResponse
import cat.pantsu.nyaapantsu.util.Utils
import kotlinx.android.synthetic.main.torrent_item.view.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
import java.util.*

class TorrentListAdapter(var activity: Activity, var torrentList: LinkedList<Torrent>) : RecyclerView.Adapter<TorrentListAdapter.TorrentListViewHolder>() {
class TorrentListAdapter(var context: Context, private var torrentList: TorrentListResponse<TorrentListModel>) : RecyclerView.Adapter<TorrentListAdapter.TorrentListViewHolder>() {

@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: TorrentListViewHolder?, position: Int) {
if (holder == null) return
val item = torrentList[position]
val item = torrentList.torrents[position]

holder.itemView.name.text = item.name
holder.itemView.uploader.text = item.username
holder.itemView.uploader.text = item.uploaderName
holder.itemView.stats.text = "S: " + item.seeders + " L: " + item.leechers
holder.itemView.date.text = item.date

Expand All @@ -44,44 +42,44 @@ class TorrentListAdapter(var activity: Activity, var torrentList: LinkedList<Tor

holder.itemView.download.setOnClickListener { _ ->
when {
!TextUtils.isEmpty(item.download) -> Utils.download(activity, holder.itemView, item.download, item.name)
else -> activity.toast(activity.getString(R.string.torrent_not_available))
!TextUtils.isEmpty(item.torrent) -> Utils.download(context as Activity, holder.itemView, item.torrent, item.name)
else -> context.toast(context.getString(R.string.torrent_not_available))
}
}

holder.itemView.copy.setOnClickListener { _ ->
val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(item.name, item.magnet)
clipboard.primaryClip = clipData
activity.toast(activity.getString(R.string.magnet_copied))
context.toast(context.getString(R.string.magnet_copied))
}

holder.itemView.cardview.setOnClickListener { _ ->
activity.startActivity<TorrentActivity>("position" to position, "type" to "search")
}
// holder.itemView.cardview.setOnClickListener { _ ->
// activity.startActivity<TorrentActivity>("position" to position, "type" to "search")
// }

when (item.status) {
2 -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
holder.itemView.cardview.setCardBackgroundColor(activity.resources.getColorStateList(R.color.colorRemake, null))
holder.itemView.cardview.setCardBackgroundColor(context.resources.getColorStateList(R.color.colorRemake, null))
} else {
holder.itemView.cardview.setCardBackgroundColor(activity.resources.getColorStateList(R.color.colorRemake))
holder.itemView.cardview.setCardBackgroundColor(context.resources.getColorStateList(R.color.colorRemake))
}

}
3 -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
holder.itemView.cardview.setCardBackgroundColor(activity.resources.getColorStateList(R.color.colorTrusted, null))
holder.itemView.cardview.setCardBackgroundColor(context.resources.getColorStateList(R.color.colorTrusted, null))
} else {
holder.itemView.cardview.setCardBackgroundColor(activity.resources.getColorStateList(R.color.colorTrusted))
holder.itemView.cardview.setCardBackgroundColor(context.resources.getColorStateList(R.color.colorTrusted))
}

}
4 -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
holder.itemView.cardview.setCardBackgroundColor(activity.resources.getColorStateList(R.color.colorAPlus, null))
holder.itemView.cardview.setCardBackgroundColor(context.resources.getColorStateList(R.color.colorAPlus, null))
} else {
holder.itemView.cardview.setCardBackgroundColor(activity.resources.getColorStateList(R.color.colorAPlus))
holder.itemView.cardview.setCardBackgroundColor(context.resources.getColorStateList(R.color.colorAPlus))
}
}
}
Expand All @@ -98,7 +96,7 @@ class TorrentListAdapter(var activity: Activity, var torrentList: LinkedList<Tor
}

override fun getItemCount(): Int {
return torrentList.size
return torrentList.torrents.size
}

class TorrentListViewHolder(view: View) : RecyclerView.ViewHolder(view)
Expand Down

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/java/cat/pantsu/nyaapantsu/api/ApiConstants.kt
@@ -0,0 +1,5 @@
package cat.pantsu.nyaapantsu.api

object ApiConstants {
const val BASE_URL = "https://nyaa.pantsu.cat/api/"
}
11 changes: 11 additions & 0 deletions app/src/main/java/cat/pantsu/nyaapantsu/api/torrent/TorrentApi.kt
@@ -0,0 +1,11 @@
package cat.pantsu.nyaapantsu.api.torrent

import cat.pantsu.nyaapantsu.mvp.model.TorrentListModel
import cat.pantsu.nyaapantsu.mvp.model.TorrentListResponse
import io.reactivex.Single


interface TorrentApi {
fun getTorrentList(): Single<TorrentListResponse<TorrentListModel>>

}
@@ -0,0 +1,18 @@
package cat.pantsu.nyaapantsu.api.torrent

import cat.pantsu.nyaapantsu.mvp.model.TorrentListModel
import cat.pantsu.nyaapantsu.mvp.model.TorrentListResponse
import io.reactivex.Single
import retrofit2.Retrofit


class TorrentRepository(val retrofit: Retrofit) : TorrentApi {
private val mainApi by lazy { retrofit.create(TorrentRetrofitApi::class.java) }

override fun getTorrentList(): Single<TorrentListResponse<TorrentListModel>> = mainApi.getTorrentList(
null, null, null, "20",
null, null, null,
null, null, null,
null, null, null,
null, null, null, null)
}
@@ -0,0 +1,31 @@
package cat.pantsu.nyaapantsu.api.torrent

import cat.pantsu.nyaapantsu.mvp.model.TorrentListModel
import cat.pantsu.nyaapantsu.mvp.model.TorrentListResponse
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Query


interface TorrentRetrofitApi {

@GET("search")
fun getTorrentList(@Query("c") c: List<String>?,
@Query("q") q: String?,
@Query("page") page: Int?,
@Query("limit") limit: String?,
@Query("userID") userID: String?,
@Query("fromID") fromID: String?,
@Query("s") s: String?,
@Query("maxage") maxage: String?,
@Query("toDate") toDate: String?,
@Query("fromDate") fromDate: String?,
@Query("dateType") dateType: String?,
@Query("minSize") minSize: String?,
@Query("maxSize") maxSize: String?,
@Query("sizeType") sizeType: String?,
@Query("sort") sort: String?,
@Query("order") order: Boolean?,
@Query("lang") lang: List<String>?): Single<TorrentListResponse<TorrentListModel>>

}

0 comments on commit 616bf5d

Please sign in to comment.