-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from Tribler/detoks
DeToks: Decentralised TikTok Skeleton
- Loading branch information
Showing
30 changed files
with
795 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="366.19dp" | ||
android:height="336.84dp" | ||
android:viewportWidth="366.19" | ||
android:viewportHeight="336.84"> | ||
<path | ||
android:pathData="m291.94,126.12c-3.36,-1.96 -6.91,-3.73 -10.58,-5.32 0.49,-4.22 0.79,-8.44 0.79,-12.66 0,-44.27 -28.01,-84.21 -69.65,-99.25 -3.3,-1.16 -6.97,0.37 -8.38,3.61 -1.41,3.24 -0.06,6.97 3.06,8.56 22.63,11.56 36.69,34.55 36.69,59.93 0,8.26 -1.53,16.39 -4.46,24.03 -17.12,-14.37 -39.2,-22.99 -63.23,-22.99s-45.56,8.44 -62.62,22.5c-2.81,-7.52 -4.28,-15.47 -4.28,-23.48 0,-25.38 14.07,-48.37 36.69,-59.93 3.12,-1.59 4.46,-5.32 3.06,-8.56s-5.08,-4.77 -8.38,-3.61c-41.65,15.04 -69.65,54.92 -69.65,99.25 0,4.16 0.24,8.38 0.73,12.6 -3.67,1.59 -7.22,3.36 -10.64,5.38C22.87,148.25 2.32,192.41 10.15,236.07c0.55,3.24 3.36,5.5 6.67,5.5 3.67,-0.06 6.6,-3 6.6,-6.67 0,-0.37 0,-0.67 -0.06,-0.98 -1.04,-25.13 11.8,-48.56 33.57,-61.15 6.85,-3.97 14.31,-6.6 22.08,-7.95 -0.86,5.14 -1.28,10.46 -1.28,15.84 0,42.62 27.21,79.01 65.13,92.77 -5.14,6.36 -11.44,11.8 -18.59,15.96 -10.21,5.87 -21.83,8.99 -33.57,8.99 -13.09,0 -25.75,-3.73 -36.69,-10.82 -2.94,-1.9 -6.85,-1.22 -8.93,1.59 -2.08,2.81 -1.65,6.79 1.04,9.05 19.02,16.02 43.17,24.83 68.12,24.83 18.41,0 36.63,-4.89 52.65,-14.13 3.36,-1.96 6.67,-4.1 9.85,-6.42 3.18,2.32 6.48,4.53 9.85,6.42 16.02,9.23 34.25,14.13 52.65,14.13 24.95,0 49.11,-8.81 68.12,-24.83 2.69,-2.26 3.12,-6.24 1.04,-9.05 -2.08,-2.81 -5.99,-3.55 -8.93,-1.59 -10.95,7.09 -23.67,10.82 -36.69,10.82 -11.74,0 -23.3,-3.12 -33.57,-8.99 -7.22,-4.16 -13.58,-9.66 -18.77,-16.14 37.67,-13.88 64.58,-50.15 64.58,-92.52 0,-5.44 -0.49,-10.76 -1.28,-15.96 8.01,1.28 15.72,4.04 22.81,8.07 22.02,12.72 34.86,36.39 33.57,61.76 -0.18,3.49 2.38,6.54 5.87,6.97 3.49,0.43 6.67,-1.96 7.28,-5.44 7.64,-43.66 -12.9,-87.88 -51.31,-110.01ZM220.21,132.3c-8.99,7.64 -19.94,12.9 -31.8,14.98 -7.89,1.41 -15.78,1.41 -23.67,0 -12.05,-2.14 -23.05,-7.46 -32.11,-15.29 11.56,-10.4 26.85,-16.69 43.6,-16.69 16.94,-0.06 32.41,6.42 43.97,17ZM110.87,180.67c0,-4.53 0.49,-8.99 1.35,-13.27 11.25,3.85 21.46,10.64 29.35,19.81 2.75,3.24 5.2,6.67 7.22,10.21 1.9,3.3 3.55,6.79 4.89,10.46 4.22,11.43 5.14,23.54 3.06,35.16 -26.6,-8.32 -45.86,-33.08 -45.86,-62.38ZM196.48,242.8c-2.08,-11.62 -1.1,-23.61 3.06,-34.92 1.35,-3.67 3,-7.22 4.89,-10.46 2.08,-3.55 4.46,-6.97 7.22,-10.21 7.77,-9.05 17.67,-15.72 28.68,-19.57 0.86,4.22 1.28,8.56 1.28,13.03 0,29.05 -18.96,53.63 -45.13,62.13Z" | ||
android:strokeWidth="17" | ||
android:fillColor="#65c8d0" | ||
android:strokeColor="#65c8d0"/> | ||
<path | ||
android:pathData="m310.81,137.43c-3.36,-1.96 -6.91,-3.73 -10.58,-5.32 0.49,-4.22 0.79,-8.44 0.79,-12.66 0,-44.27 -28.01,-84.21 -69.65,-99.25 -3.3,-1.16 -6.97,0.37 -8.38,3.61 -1.41,3.24 -0.06,6.97 3.06,8.56 22.63,11.56 36.69,34.55 36.69,59.93 0,8.26 -1.53,16.39 -4.46,24.03 -17.12,-14.37 -39.2,-22.99 -63.23,-22.99s-45.56,8.44 -62.62,22.5c-2.81,-7.52 -4.28,-15.47 -4.28,-23.48 0,-25.38 14.07,-48.37 36.69,-59.93 3.12,-1.59 4.46,-5.32 3.06,-8.56s-5.08,-4.77 -8.38,-3.61c-41.65,15.04 -69.65,54.92 -69.65,99.25 0,4.16 0.24,8.38 0.73,12.6 -3.67,1.59 -7.22,3.36 -10.64,5.38 -38.22,22.08 -58.77,66.23 -50.94,109.89 0.55,3.24 3.36,5.5 6.67,5.5 3.67,-0.06 6.6,-3 6.6,-6.67 0,-0.37 0,-0.67 -0.06,-0.98 -1.04,-25.13 11.8,-48.56 33.57,-61.15 6.85,-3.97 14.31,-6.6 22.08,-7.95 -0.86,5.14 -1.28,10.46 -1.28,15.84 0,42.62 27.21,79.01 65.13,92.77 -5.14,6.36 -11.44,11.8 -18.59,15.96 -10.21,5.87 -21.83,8.99 -33.57,8.99 -13.09,0 -25.75,-3.73 -36.69,-10.82 -2.94,-1.9 -6.85,-1.22 -8.93,1.59 -2.08,2.81 -1.65,6.79 1.04,9.05 19.02,16.02 43.17,24.83 68.12,24.83 18.41,0 36.63,-4.89 52.65,-14.13 3.36,-1.96 6.67,-4.1 9.85,-6.42 3.18,2.32 6.48,4.53 9.85,6.42 16.02,9.23 34.25,14.13 52.65,14.13 24.95,0 49.11,-8.81 68.12,-24.83 2.69,-2.26 3.12,-6.24 1.04,-9.05 -2.08,-2.81 -5.99,-3.55 -8.93,-1.59 -10.95,7.09 -23.67,10.82 -36.69,10.82 -11.74,0 -23.3,-3.12 -33.57,-8.99 -7.22,-4.16 -13.58,-9.66 -18.77,-16.14 37.67,-13.88 64.58,-50.15 64.58,-92.52 0,-5.44 -0.49,-10.76 -1.28,-15.96 8.01,1.28 15.72,4.04 22.81,8.07 22.02,12.72 34.86,36.39 33.57,61.76 -0.18,3.49 2.38,6.54 5.87,6.97 3.49,0.43 6.67,-1.96 7.28,-5.44 7.64,-43.66 -12.9,-87.88 -51.31,-110.01ZM239.08,143.61c-8.99,7.64 -19.94,12.9 -31.8,14.98 -7.89,1.41 -15.78,1.41 -23.67,0 -12.05,-2.14 -23.05,-7.46 -32.11,-15.29 11.56,-10.4 26.85,-16.69 43.6,-16.69 16.94,-0.06 32.41,6.42 43.97,17ZM129.74,191.98c0,-4.53 0.49,-8.99 1.35,-13.27 11.25,3.85 21.46,10.64 29.35,19.81 2.75,3.24 5.2,6.67 7.22,10.21 1.9,3.3 3.55,6.79 4.89,10.46 4.22,11.43 5.14,23.54 3.06,35.16 -26.6,-8.32 -45.86,-33.08 -45.86,-62.38ZM215.35,254.11c-2.08,-11.62 -1.1,-23.61 3.06,-34.92 1.35,-3.67 3,-7.22 4.89,-10.46 2.08,-3.55 4.46,-6.97 7.22,-10.21 7.77,-9.05 17.67,-15.72 28.68,-19.57 0.86,4.22 1.28,8.56 1.28,13.03 0,29.05 -18.96,53.63 -45.13,62.13Z" | ||
android:strokeWidth="5" | ||
android:fillColor="#ed1c53" | ||
android:strokeColor="#ed1c53"/> | ||
<path | ||
android:pathData="m299.94,129.72c-3.36,-1.96 -6.91,-3.73 -10.58,-5.32 0.49,-4.22 0.79,-8.44 0.79,-12.66 0,-44.27 -28.01,-84.21 -69.65,-99.25 -3.3,-1.16 -6.97,0.37 -8.38,3.61 -1.41,3.24 -0.06,6.97 3.06,8.56 22.63,11.56 36.69,34.55 36.69,59.93 0,8.26 -1.53,16.39 -4.46,24.03 -17.12,-14.37 -39.2,-22.99 -63.23,-22.99s-45.56,8.44 -62.62,22.5c-2.81,-7.52 -4.28,-15.47 -4.28,-23.48 0,-25.38 14.07,-48.37 36.69,-59.93 3.12,-1.59 4.46,-5.32 3.06,-8.56s-5.08,-4.77 -8.38,-3.61c-41.65,15.04 -69.65,54.92 -69.65,99.25 0,4.16 0.24,8.38 0.73,12.6 -3.67,1.59 -7.22,3.36 -10.64,5.38 -38.22,22.08 -58.77,66.23 -50.94,109.89 0.55,3.24 3.36,5.5 6.67,5.5 3.67,-0.06 6.6,-3 6.6,-6.67 0,-0.37 0,-0.67 -0.06,-0.98 -1.04,-25.13 11.8,-48.56 33.57,-61.15 6.85,-3.97 14.31,-6.6 22.08,-7.95 -0.86,5.14 -1.28,10.46 -1.28,15.84 0,42.62 27.21,79.01 65.13,92.77 -5.14,6.36 -11.44,11.8 -18.59,15.96 -10.21,5.87 -21.83,8.99 -33.57,8.99 -13.09,0 -25.75,-3.73 -36.69,-10.82 -2.94,-1.9 -6.85,-1.22 -8.93,1.59 -2.08,2.81 -1.65,6.79 1.04,9.05 19.02,16.02 43.17,24.83 68.12,24.83 18.41,0 36.63,-4.89 52.65,-14.13 3.36,-1.96 6.67,-4.1 9.85,-6.42 3.18,2.32 6.48,4.53 9.85,6.42 16.02,9.23 34.25,14.13 52.65,14.13 24.95,0 49.11,-8.81 68.12,-24.83 2.69,-2.26 3.12,-6.24 1.04,-9.05 -2.08,-2.81 -5.99,-3.55 -8.93,-1.59 -10.95,7.09 -23.67,10.82 -36.69,10.82 -11.74,0 -23.3,-3.12 -33.57,-8.99 -7.22,-4.16 -13.58,-9.66 -18.77,-16.14 37.67,-13.88 64.58,-50.15 64.58,-92.52 0,-5.44 -0.49,-10.76 -1.28,-15.96 8.01,1.28 15.72,4.04 22.81,8.07 22.02,12.72 34.86,36.39 33.57,61.76 -0.18,3.49 2.38,6.54 5.87,6.97 3.49,0.43 6.67,-1.96 7.28,-5.44 7.64,-43.66 -12.9,-87.88 -51.31,-110.01ZM228.21,135.9c-8.99,7.64 -19.94,12.9 -31.8,14.98 -7.89,1.41 -15.78,1.41 -23.67,0 -12.05,-2.14 -23.05,-7.46 -32.11,-15.29 11.56,-10.4 26.85,-16.69 43.6,-16.69 16.94,-0.06 32.41,6.42 43.97,17ZM118.87,184.27c0,-4.53 0.49,-8.99 1.35,-13.27 11.25,3.85 21.46,10.64 29.35,19.81 2.75,3.24 5.2,6.67 7.22,10.21 1.9,3.3 3.55,6.79 4.89,10.46 4.22,11.43 5.14,23.54 3.06,35.16 -26.6,-8.32 -45.86,-33.08 -45.86,-62.38ZM204.48,246.4c-2.08,-11.62 -1.1,-23.61 3.06,-34.92 1.35,-3.67 3,-7.22 4.89,-10.46 2.08,-3.55 4.46,-6.97 7.22,-10.21 7.77,-9.05 17.67,-15.72 28.68,-19.57 0.86,4.22 1.28,8.56 1.28,13.03 0,29.05 -18.96,53.63 -45.13,62.13Z" | ||
android:fillColor="#010101"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 33 | ||
|
||
defaultConfig { | ||
minSdkVersion 22 | ||
targetSdkVersion 33 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles 'consumer-rules.pro' | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
allWarningsAsErrors = true | ||
} | ||
|
||
|
||
buildFeatures { | ||
viewBinding = true | ||
} | ||
namespace 'nl.tudelft.trustchain.detoks' | ||
} | ||
|
||
dependencies { | ||
implementation project(':common') | ||
|
||
// AndroidX | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'androidx.core:core-ktx:1.9.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
implementation "androidx.recyclerview:recyclerview:1.2.1" | ||
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" | ||
implementation "androidx.navigation:navigation-ui-ktx:$nav_version" | ||
implementation "androidx.fragment:fragment-ktx:$fragment_version" | ||
implementation "androidx.preference:preference:1.2.0" | ||
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" | ||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" | ||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" | ||
|
||
// Material | ||
implementation 'com.google.android.material:material:1.8.0' | ||
|
||
// Kotlin | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" | ||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" | ||
|
||
// Logging | ||
implementation 'io.github.microutils:kotlin-logging:1.7.7' | ||
implementation 'com.github.tony19:logback-android:2.0.0' | ||
|
||
implementation 'com.github.MattSkala:recyclerview-itemadapter:0.4' | ||
|
||
// Testing | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
|
||
// TODO fix direct import, this should rely on common. | ||
// BitTorrent | ||
implementation files('../common/libs/jlibtorrent-' + jlibtorrent_version + '.jar') | ||
implementation files('../common/libs/jlibtorrent-android-arm64-' + jlibtorrent_version + '.jar') | ||
implementation files('../common/libs/jlibtorrent-android-arm-' + jlibtorrent_version + '.jar') | ||
implementation files('../common/libs/jlibtorrent-android-x86-' + jlibtorrent_version + '.jar') | ||
implementation files('../common/libs/jlibtorrent-android-x86_64-' + jlibtorrent_version + '.jar') | ||
|
||
implementation 'com.devbrackets.android:exomedia:4.3.0' | ||
} | ||
|
||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { | ||
kotlinOptions.freeCompilerArgs += [ | ||
"-opt-in=kotlin.RequiresOptIn", "-Werror" | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | ||
|
||
<application> | ||
<activity | ||
android:name="nl.tudelft.trustchain.detoks.DeToksActivity" | ||
android:configChanges="keyboardHidden|orientation|screenSize" | ||
android:label="@string/title_activity_main_detoks" | ||
android:theme="@style/Fullscreen" | ||
android:windowSoftInputMode="stateHidden" /> | ||
</application> | ||
|
||
</manifest> |
91 changes: 91 additions & 0 deletions
91
detoks/src/main/java/nl/tudelft/trustchain/detoks/DeToksFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package nl.tudelft.trustchain.detoks | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.View | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import kotlinx.android.synthetic.main.fragment_detoks.* | ||
import mu.KotlinLogging | ||
import nl.tudelft.trustchain.common.ui.BaseFragment | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
|
||
class DeToksFragment : BaseFragment(R.layout.fragment_detoks) { | ||
private lateinit var torrentManager: TorrentManager | ||
private val logger = KotlinLogging.logger {} | ||
private var previousVideoAdapterIndex = 0 | ||
|
||
private val torrentDir: String | ||
get() = "${requireActivity().cacheDir.absolutePath}/torrent" | ||
private val mediaCacheDir: String | ||
get() = "${requireActivity().cacheDir.absolutePath}/media" | ||
|
||
private fun cacheDefaultTorrent() { | ||
try { | ||
val dir1 = File(mediaCacheDir) | ||
if (!dir1.exists()) { | ||
dir1.mkdirs() | ||
} | ||
val dir2 = File(torrentDir) | ||
if (!dir2.exists()) { | ||
dir2.mkdirs() | ||
} | ||
val file = File("$torrentDir/$DEFAULT_TORRENT_FILE") | ||
if (!file.exists()) { | ||
val outputStream = FileOutputStream(file) | ||
val ins = requireActivity().resources.openRawResource(R.raw.detoks) | ||
outputStream.write(ins.readBytes()) | ||
ins.close() | ||
outputStream.close() | ||
} | ||
} catch (e: Exception) { | ||
Log.e("DeToks", "Failed to cache default torrent: $e") | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
cacheDefaultTorrent() | ||
torrentManager = TorrentManager( | ||
File("${requireActivity().cacheDir.absolutePath}/media"), | ||
File("${requireActivity().cacheDir.absolutePath}/torrent"), | ||
DEFAULT_CACHING_AMOUNT | ||
) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewPagerVideos.adapter = VideosAdapter(torrentManager) | ||
viewPagerVideos.currentItem = 0 | ||
onPageChangeCallback() | ||
} | ||
|
||
/** | ||
* This functions allows for looping back to start of the video pool. | ||
*/ | ||
private fun onPageChangeCallback() { | ||
viewPagerVideos.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { | ||
override fun onPageScrollStateChanged(state: Int) { | ||
super.onPageScrollStateChanged(state) | ||
|
||
if (state == ViewPager2.SCROLL_STATE_IDLE) { | ||
when (viewPagerVideos.currentItem - previousVideoAdapterIndex) { | ||
1 -> torrentManager.notifyIncrease() | ||
-1 -> torrentManager.notifyDecrease() | ||
0 -> {} // Do nothing | ||
else -> { | ||
logger.error { "Something went wrong with the video adapter index" } | ||
} | ||
} | ||
previousVideoAdapterIndex = viewPagerVideos.currentItem | ||
} | ||
} | ||
}) | ||
} | ||
|
||
companion object { | ||
const val DEFAULT_CACHING_AMOUNT = 2 | ||
const val DEFAULT_TORRENT_FILE = "detoks.torrent" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
detoks/src/main/java/nl/tudelft/trustchain/detoks/DeToksMainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package nl.tudelft.trustchain.detoks | ||
|
||
import android.os.Bundle | ||
import nl.tudelft.trustchain.common.BaseActivity | ||
|
||
class DeToksActivity : BaseActivity() { | ||
override val navigationGraph = R.navigation.nav_graph_detoks | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val actionBar = supportActionBar | ||
actionBar!!.hide() | ||
} | ||
} |
Oops, something went wrong.