├── app ├── .gitignore ├── screenshots │ └── search_screenshot.jpg ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── values │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable │ │ │ │ ├── cursor_white.xml │ │ │ │ ├── ic_arrow_upward_white_24dp.xml │ │ │ │ ├── ic_arrow_downward_white_24dp.xml │ │ │ │ ├── ic_save_white_24dp.xml │ │ │ │ ├── ic_date_range_white_24dp.xml │ │ │ │ └── ic_search_black_24dp.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── item_network_state.xml │ │ │ │ ├── fragment_search.xml │ │ │ │ └── item_search_result.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── masterwok │ │ │ │ └── tpbsearchandroid │ │ │ │ ├── extensions │ │ │ │ ├── ViewExtensions.kt │ │ │ │ ├── ContextExtensions.kt │ │ │ │ └── RecyclerViewExtensions.kt │ │ │ │ ├── activities │ │ │ │ └── MainActivity.kt │ │ │ │ ├── paging │ │ │ │ ├── search │ │ │ │ │ ├── TorrentResultDiffCallback.kt │ │ │ │ │ ├── TpbDataFactory.kt │ │ │ │ │ ├── TpbItemViewHolder.kt │ │ │ │ │ └── TpbDataSource.kt │ │ │ │ └── common │ │ │ │ │ ├── NetworkState.kt │ │ │ │ │ ├── NetworkStateViewHolder.kt │ │ │ │ │ └── NetworkPagedListAdapter.kt │ │ │ │ ├── viewmodels │ │ │ │ └── SearchViewModel.kt │ │ │ │ └── fragments │ │ │ │ └── SearchFragment.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── masterwok │ │ │ └── tpbsearchandroid │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── masterwok │ │ └── tpbsearchandroid │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── tpbsearchandroid ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── masterwok │ │ │ └── tpbsearchandroid │ │ │ ├── models │ │ │ ├── QueryResult.kt │ │ │ └── TorrentResult.kt │ │ │ ├── common │ │ │ ├── AndroidJob.kt │ │ │ ├── InterruptAsync.kt │ │ │ └── extensions │ │ │ │ └── DeferredExtensions.kt │ │ │ ├── contracts │ │ │ └── QueryService.kt │ │ │ ├── services │ │ │ └── QueryService.kt │ │ │ ├── extensions │ │ │ └── ElementExtensions.kt │ │ │ └── constants │ │ │ └── Hosts.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── masterwok │ │ │ └── tpbsearchandroid │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── masterwok │ │ └── tpbsearchandroid │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── vcs.xml ├── runConfigurations.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── gradle.properties ├── LICENSE ├── .gitignore ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /tpbsearchandroid/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':tpbsearchandroid' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/screenshots/search_screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/screenshots/search_screenshot.jpg -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | tpbsearchandroid 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/masterwok/tpb-search-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FC0DEA 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TPB Search Android 3 | RETRY 4 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/cursor_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_upward_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_downward_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/masterwok/tpbsearchandroid/extensions/ViewExtensions.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.extensions 2 | 3 | import android.view.View 4 | 5 | /** 6 | * Dismiss soft input (keyboard) from the window using a [View] context. 7 | */ 8 | fun View.dismissKeyboard() = context 9 | .getInputMethodManager() 10 | .hideSoftInputFromWindow( 11 | windowToken 12 | , 0 13 | ) 14 | -------------------------------------------------------------------------------- /app/src/test/java/com/masterwok/tpbsearchandroid/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/masterwok/tpbsearchandroid/activities/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.activities 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | import com.masterwok.tpbsearchandroid.R 6 | 7 | class MainActivity : AppCompatActivity() { 8 | 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | setContentView(R.layout.activity_main) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_save_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/test/java/com/masterwok/tpbsearchandroid/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_date_range_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/masterwok/tpbsearchandroid/paging/search/TorrentResultDiffCallback.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.paging.search 2 | 3 | import android.support.v7.util.DiffUtil 4 | import com.masterwok.tpbsearchandroid.models.TorrentResult 5 | 6 | val TorrentResultDiffCallback = object : DiffUtil.ItemCallback() { 7 | override fun areItemsTheSame( 8 | oldItem: TorrentResult? 9 | , newItem: TorrentResult? 10 | ): Boolean = oldItem == newItem 11 | 12 | override fun areContentsTheSame( 13 | oldItem: TorrentResult? 14 | , newItem: TorrentResult? 15 | ): Boolean = oldItem?.magnet == newItem?.magnet 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/java/com/masterwok/tpbsearchandroid/models/QueryResult.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.models 2 | 3 | data class QueryResult( 4 | var state: State = State.PENDING 5 | , var pageIndex: Int = 0 6 | , var lastPageIndex: Int = 0 7 | , var items: List = ArrayList() 8 | ) { 9 | enum class State { 10 | PENDING, 11 | SUCCESS, 12 | INVALID, 13 | ERROR 14 | } 15 | 16 | 17 | fun isSuccessful(): Boolean = state == State.SUCCESS 18 | 19 | fun getItemCount(): Int = items.size 20 | 21 | override fun toString(): String = "State: $state" + 22 | ", Page: $pageIndex/$lastPageIndex" + 23 | ", Item Count: ${items.size}" 24 | } 25 | 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/java/com/masterwok/tpbsearchandroid/common/AndroidJob.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.common 2 | 3 | import android.arch.lifecycle.Lifecycle 4 | import android.arch.lifecycle.LifecycleObserver 5 | import android.arch.lifecycle.OnLifecycleEvent 6 | import kotlinx.coroutines.experimental.Job 7 | 8 | 9 | /** 10 | * A Kotlin coroutine [@see Job] that cancels itself when the lifecycle it's 11 | * bound to is destroyed. This class can be used as a parent job to prevent 12 | * memory leaks and null reference exceptions. 13 | */ 14 | class AndroidJob(lifecycle: Lifecycle) : Job by Job(), LifecycleObserver { 15 | init { 16 | lifecycle.addObserver(this) 17 | } 18 | 19 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 20 | fun destroy() = cancel() 21 | } -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/java/com/masterwok/tpbsearchandroid/models/TorrentResult.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.models 2 | 3 | /** 4 | * A single result item. This represents a single row from the search 5 | * results on the pirate bay. 6 | */ 7 | data class TorrentResult( 8 | val title: String 9 | , val magnet: String 10 | , val infoHash: String 11 | , val seeders: Int 12 | , val leechers: Int 13 | , val displayUploadedOn: String 14 | , val displaySize: String 15 | ) { 16 | override fun toString(): String { 17 | return "title: $title" + 18 | ", seeders: $seeders" + 19 | ", leechers: $leechers" + 20 | ", infoHash: $infoHash" + 21 | ", magnet: $magnet" 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/masterwok/tpbsearchandroid/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.masterwok.tpbsearchandroid", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /tpbsearchandroid/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/masterwok/tpbsearchandroid/paging/common/NetworkState.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.paging.common 2 | 3 | 4 | /** 5 | * This enumeration represents the current state of some network request. 6 | * 7 | */ 8 | enum class NetworkState(val value: Int) { 9 | 10 | /** 11 | * Request is in progress. 12 | */ 13 | LOADING(0), 14 | 15 | /** 16 | * Request has completed successfully. 17 | */ 18 | LOADED(1), 19 | 20 | /** 21 | * Request resulted in an error. 22 | */ 23 | ERROR(2); 24 | 25 | companion object { 26 | private val map = NetworkState 27 | .values() 28 | .associateBy(NetworkState::value) 29 | 30 | /** 31 | * Convert an [Int] [value] to a [NetworkState]. 32 | */ 33 | fun getValue(value: Int) = map[value] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/masterwok/tpbsearchandroid/extensions/ContextExtensions.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.extensions 2 | 3 | import android.content.Context 4 | import android.os.Build 5 | import android.support.annotation.ColorRes 6 | import android.support.v4.content.ContextCompat 7 | import android.view.inputmethod.InputMethodManager 8 | 9 | /** 10 | * Get the [InputMethodManager] using some [Context]. 11 | */ 12 | fun Context.getInputMethodManager(): InputMethodManager { 13 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 14 | return getSystemService(InputMethodManager::class.java) 15 | } 16 | 17 | return getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 18 | } 19 | 20 | 21 | /** 22 | * Get color using [ContextCompat] and the provided [id]. 23 | */ 24 | internal fun Context.getCompatColor(@ColorRes id: Int) = ContextCompat.getColor(this, id) 25 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/androidTest/java/com/masterwok/tpbsearchandroid/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.masterwok.tpbsearchandroid.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #313A3B 4 | #3F4B4C 5 | #5D5179 6 | 7 | #4C5B5C 8 | #3891A6 9 | #94E495 10 | #92c9b1 11 | #5D5179 12 | #EF6F6C 13 | #F5EE9E 14 | 15 | #FF000000 16 | #FFFFFFFF 17 | 18 | #CF000000 19 | 20 | @color/castPurple 21 | #7F000000 22 | 23 | #7F000000 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/masterwok/tpbsearchandroid/extensions/RecyclerViewExtensions.kt: -------------------------------------------------------------------------------- 1 | package com.masterwok.tpbsearchandroid.extensions 2 | 3 | import android.support.v7.widget.RecyclerView 4 | 5 | /** 6 | * Disable the initial scroll that occurs when inserting items into a list when the 7 | * initial scroll position is 0. This seems to occur when using a [@see PagedListAdapter] 8 | * however this may be limited to some use cases. If a scroll view is auto scrolling to 9 | * the bottom when items are inserted, then try applying this extension to the adapter. 10 | */ 11 | fun RecyclerView.Adapter.disableInitialInsertScroll( 12 | layoutManager: RecyclerView.LayoutManager 13 | ) { 14 | registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { 15 | override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { 16 | if (positionStart == 0) { 17 | layoutManager.scrollToPosition(0) 18 | } 19 | } 20 | }) 21 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/java/com/masterwok/tpbsearchandroid/contracts/QueryService.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("EXPERIMENTAL_FEATURE_WARNING") 2 | 3 | package com.masterwok.tpbsearchandroid.contracts 4 | 5 | import com.masterwok.tpbsearchandroid.models.QueryResult 6 | import com.masterwok.tpbsearchandroid.models.TorrentResult 7 | 8 | const val DefaultRequestTimeout = 5000 9 | const val DefaultQueryTimeout = 10000L 10 | 11 | 12 | /** 13 | * Contract that provides simple interface for querying The Pirate Bay. 14 | */ 15 | interface QueryService { 16 | 17 | /** 18 | * Simultaneously query each host using the provided [query] and [pageIndex]. The [query] 19 | * is the search query, and the [pageIndex] is the result page index. Each request will 20 | * timeout after some [requestTimeoutMs] and the whole query will timeout after some 21 | * [queryTimeoutMs]. 22 | */ 23 | suspend fun query( 24 | query: String 25 | , pageIndex: Int = 0 26 | , queryTimeoutMs: Long = DefaultQueryTimeout 27 | , requestTimeoutMs: Int = DefaultRequestTimeout 28 | ): QueryResult 29 | 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jonathan Trowbridge 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 14 | 15 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tpbsearchandroid/src/main/java/com/masterwok/tpbsearchandroid/common/InterruptAsync.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("EXPERIMENTAL_FEATURE_WARNING") 2 | 3 | package com.masterwok.tpbsearchandroid.common 4 | 5 | import kotlinx.coroutines.experimental.* 6 | 7 | internal fun interruptAsync( 8 | executorCoroutineDispatcher: ExecutorCoroutineDispatcher 9 | , start: CoroutineStart = CoroutineStart.DEFAULT 10 | , parent: Job? = null 11 | , onCompletion: CompletionHandler? = null 12 | , block: suspend CoroutineScope.() -> T 13 | ): Deferred { 14 | var thread: Thread? = null 15 | 16 | val deferred = async( 17 | context = executorCoroutineDispatcher 18 | , start = start 19 | , parent = parent 20 | , onCompletion = onCompletion 21 | ) { 22 | thread = Thread.currentThread() 23 | 24 | return@async block() 25 | } 26 | 27 | deferred.invokeOnCompletion(true, true) { 28 | if (deferred.isCancelled 29 | && thread != null 30 | && thread?.isAlive == true 31 | ) { 32 | thread?.interrupt() 33 | thread = null 34 | } 35 | } 36 | 37 | return deferred 38 | } 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_network_state.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 25 | 26 |