diff --git a/app/app.iml b/app/app.iml index 534d63c..233e049 100644 --- a/app/app.iml +++ b/app/app.iml @@ -50,19 +50,19 @@ - - + + - + - + @@ -97,13 +97,6 @@ - - - - - - - @@ -111,32 +104,46 @@ - + + + + + + + + + + - + + - - + + + - + - + + + + - + @@ -145,36 +152,37 @@ - - + - - - + + + - + + + - - - + + + - + + - + + - - - + diff --git a/app/build.gradle b/app/build.gradle index 9e7dcdb..0830b1d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - buildToolsVersion '27.0.3' + buildToolsVersion '28.0.2' compileOptions { sourceCompatibility JavaVersion.VERSION_1_6 targetCompatibility JavaVersion.VERSION_1_6 @@ -29,11 +29,11 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" - implementation 'com.android.support:appcompat-v7:27.1.1' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:27.1.0' implementation 'com.android.support.constraint:constraint-layout:1.1.2' - implementation 'com.android.support:support-v4:27.1.1' - implementation 'com.android.support:design:27.1.1' + implementation 'com.android.support:support-v4:27.1.0' + implementation 'com.android.support:design:27.1.0' implementation 'com.squareup.picasso:picasso:2.71828' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' diff --git a/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt b/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt index 11617e0..b58ab01 100644 --- a/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/MainActivity.kt @@ -29,6 +29,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte private lateinit var viewManager: RecyclerView.LayoutManager val client: Videos = Videos() private lateinit var lastItem: MenuItem + private lateinit var subItem: MenuItem lateinit var myMenu: Menu val _db = Database(this) var section: String = "" @@ -89,6 +90,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte "local" -> this.getLocalVideos() "popular" -> this.getPopularVideos() "last" -> this.getLastVideos() + "sub" -> this.getSubscriptionVideos() "my_videos" -> { if(ManagerSingleton.token.token != "") this.getMyVideos() @@ -98,6 +100,23 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } } + fun getSubscriptionVideos(){ + if(ManagerSingleton.user.status != 1){ + ManagerSingleton.Toast("Inicia session primero") + startActivity(Intent(this, LoginActivity::class.java)) + return + } + swipeContainer.isRefreshing = true + section = "sub" + setTitle(R.string.title_subscriptions) + AsyncTask.execute { + val videos = client.videoSubscriptions(ManagerSingleton.token.token) + runOnUiThread { + this.setData(videos) + } + } + } + // Last videos fun getLastVideos(){ swipeContainer.isRefreshing = true @@ -202,6 +221,9 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte lastItem = item // item.isChecked = true when (item.itemId) { + R.id.nav_subscriptions->{ + getSubscriptionVideos() + } R.id.nav_popular-> { getPopularVideos() } diff --git a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt index 47b2dc3..042e0ea 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ReproductorActivity.kt @@ -1,14 +1,18 @@ package org.libre.agosto.p2play +import android.os.AsyncTask import android.support.v7.app.AppCompatActivity import android.os.Bundle +import android.os.Looper import android.util.Log import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.activity_reproductor.* +import org.libre.agosto.p2play.ajax.Subscriptions import org.libre.agosto.p2play.models.VideoModel class ReproductorActivity : AppCompatActivity() { lateinit var video:VideoModel + private val _subsciption: Subscriptions = Subscriptions() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -17,6 +21,12 @@ class ReproductorActivity : AppCompatActivity() { videoView.settings.javaScriptEnabled = true videoView.settings.allowContentAccess = true + videoView.settings.javaScriptCanOpenWindowsAutomatically = true + videoView.settings.allowFileAccess = true + videoView.settings.allowFileAccessFromFileURLs = true + videoView.settings.allowUniversalAccessFromFileURLs = true + videoView.settings.domStorageEnabled = true + try { this.video = this.intent.extras.getSerializable("video") as VideoModel tittleVideoTxt.text = this.video.name @@ -34,6 +44,21 @@ class ReproductorActivity : AppCompatActivity() { Log.d("Error", err?.message) } - subscribeBtn.setOnClickListener { ManagerSingleton.Toast(getString(R.string.comming)) } + // subscribeBtn.setOnClickListener { ManagerSingleton.Toast(getString(R.string.comming)) } + subscribeBtn.setOnClickListener { subscribe() } + } + + fun subscribe(){ + val account = this.video.userUuid+"@"+this.video.userHost + AsyncTask.execute { + if (Looper.myLooper() == null) + Looper.prepare() + val res = this._subsciption.subscribe(ManagerSingleton.token.token, account) + if (res == 1) { + runOnUiThread { + ManagerSingleton.Toast(getString(R.string.subscribeMsg)) + } + } + } } } diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Subscriptions.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Subscriptions.kt new file mode 100644 index 0000000..b0f0cc5 --- /dev/null +++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Subscriptions.kt @@ -0,0 +1,23 @@ +package org.libre.agosto.p2play.ajax + +class Subscriptions: Client() { + + fun subscribe(token: String, account: String):Int{ + var con=this._newCon("users/me/subscriptions","POST", token) + val params:String= "uri=$account" + con.outputStream.write(params.toByteArray()) + var response = 0 + + try { + if (con.responseCode == 204) { + response = 1 + } + } + catch (err: Exception){ + err.printStackTrace() + response = -1 + } + + return response + } +} \ No newline at end of file diff --git a/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt b/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt index 7f87afa..7f11381 100644 --- a/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt +++ b/app/src/main/java/org/libre/agosto/p2play/ajax/Videos.kt @@ -42,13 +42,13 @@ class Videos: Client() { "views"->{ video.views = data.nextInt() } - "account"->{ + "channel"->{ data.beginObject() while (data.hasNext()){ val acKey = data.nextName() when(acKey.toString()){ - "name"->video.username=data.nextString() - "avatar"->{ + "displayName"-> video.username=data.nextString() + "avatar"-> { if(data.peek() == JsonToken.BEGIN_OBJECT){ data.beginObject() while (data.hasNext()){ @@ -64,6 +64,8 @@ class Videos: Client() { data.skipValue() } + "uuid" -> video.userUuid = data.nextString() + "host" -> video.userHost = data.nextString() else-> data.skipValue() } } @@ -133,4 +135,21 @@ class Videos: Client() { } return videos } + + fun videoSubscriptions(token: String): ArrayList{ + var con=this._newCon("users/me/subscriptions/videos","GET", token) + var videos = arrayListOf() + try { + if (con.responseCode == 200) { + var response = InputStreamReader(con.inputStream) + var data = JsonReader(response) + videos = parseVideos(data) + } + } catch(err:Exception){ + err?.printStackTrace() + Log.d("TypeErr",err?.message ,err.cause) + Log.d("Error","fallo la coneccion") + } + return videos + } } \ No newline at end of file diff --git a/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt b/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt index 0513e56..f7abe52 100644 --- a/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt +++ b/app/src/main/java/org/libre/agosto/p2play/models/VideoModel.kt @@ -3,12 +3,14 @@ package org.libre.agosto.p2play.models import java.io.Serializable class VideoModel( - var name:String="", - var description:String="", - var thumbUrl:String="", - var userImageUrl:String="", - var embedUrl:String="", - var duration:Number=0, - var username:String="", - var views:Number=0 + var name: String = "", + var description: String = "", + var thumbUrl: String = "", + var userImageUrl: String = "", + var embedUrl: String = "", + var duration: Number = 0, + var username: String = "", + var views: Number = 0, + var userUuid: String = "", + var userHost: String = "" ):Serializable \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_video_library_black_24dp.xml b/app/src/main/res/drawable/ic_video_library_black_24dp.xml new file mode 100644 index 0000000..f808aee --- /dev/null +++ b/app/src/main/res/drawable/ic_video_library_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_reproductor.xml b/app/src/main/res/layout/activity_reproductor.xml index 21f44ad..427aa4f 100644 --- a/app/src/main/res/layout/activity_reproductor.xml +++ b/app/src/main/res/layout/activity_reproductor.xml @@ -111,8 +111,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" - android:text="@string/subscribeBtn" - android:visibility="invisible" /> + android:text="@string/subscribeBtn" /> + + Subscriptions Recent videos Popular videos Local videos diff --git a/app/src/main/res/values/menu.xml b/app/src/main/res/values/menu.xml index 23b18fd..c25957e 100644 --- a/app/src/main/res/values/menu.xml +++ b/app/src/main/res/values/menu.xml @@ -1,5 +1,6 @@ + Subscriptions Popular Recent Local diff --git a/app/src/main/res/values/reproductorActivity.xml b/app/src/main/res/values/reproductorActivity.xml index fc859c8..05cd86b 100644 --- a/app/src/main/res/values/reproductorActivity.xml +++ b/app/src/main/res/values/reproductorActivity.xml @@ -5,5 +5,8 @@ Dislike Share Report + + Subscribe + You are subscribed to this channel \ No newline at end of file