Skip to content

Commit

Permalink
Merge pull request #1 from wimvdputten/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wimvdputten authored Jan 17, 2021
2 parents 186017c + 0739866 commit d43088c
Show file tree
Hide file tree
Showing 54 changed files with 1,720 additions and 223 deletions.
43 changes: 37 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "30.0.1"
buildToolsVersion "30.0.2"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
defaultConfig {
applicationId "xo.william.pixeldrain"
minSdkVersion 21
Expand All @@ -24,14 +31,38 @@ android {
}
}


dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
def nav_version = "2.3.0"

def room_version = "2.2.5"
def fuel_version = "2.2.3"
implementation 'com.google.android.exoplayer:exoplayer:2.12.3'

implementation "androidx.room:room-runtime:$room_version"
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // or "kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC" // JVM dependency

kapt("androidx.room:room-compiler:$room_version")


implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

implementation "com.github.kittinunf.fuel:fuel:$fuel_version"

androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xo.william.pixeldrain">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".LoginActivity" />
<activity android:name=".FileViewActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions app/src/main/java/xo/william/pixeldrain/FileViewActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package xo.william.pixeldrain

import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import com.bumptech.glide.Glide
import com.github.kittinunf.fuel.core.requests.CancellableRequest
import com.github.kittinunf.fuel.core.requests.tryCancel
import com.github.kittinunf.result.Result
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ui.PlayerView
import kotlinx.android.synthetic.main.activity_file_view.*
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import xo.william.pixeldrain.api.FuelService
import xo.william.pixeldrain.fileList.InfoModel


class FileViewActivity : AppCompatActivity() {

private val format = Json { ignoreUnknownKeys = true }
private lateinit var infoModel: InfoModel;

private lateinit var exoPlayer: SimpleExoPlayer
private lateinit var request: CancellableRequest

private var textLiveData = MutableLiveData<String>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_file_view)
setSupportActionBar(sub_toolbar)

supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
}

val infoModelString: String? = intent.getStringExtra("infoModel")
if (infoModelString !== null) {
infoModel = format.decodeFromString(infoModelString);
} else {
infoModel = InfoModel("")
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
}

loadFile()
}

private fun loadFile() {
val type = infoModel.mime_type;
if (type.contains("image")) {
loadImage();
}
if (type.contains("video") || type.contains("audio")) {
loadVideo()
}
if (type.contains("text")) {
loadText();
}
}

private fun loadImage() {
val imageFile = findViewById<ImageView>(R.id.imageFile)
val fileProgress = findViewById<ProgressBar>(R.id.fileProgressBar);
try {
val urlString = infoModel.getFileUrl()
imageFile.visibility = View.VISIBLE
imageFile.contentDescription = infoModel.name;
Glide.with(this).load(urlString).fitCenter().into(imageFile)
fileProgress.visibility = View.GONE
} catch (e: Exception) {
fileProgress.visibility = View.GONE
Toast.makeText(this, "Error: ${e.message}", Toast.LENGTH_LONG).show();
Log.e("loadImage", "error: " + infoModel.getThumbnailUrl() + " " + e.message)
}
}

private fun loadVideo() {
val fileProgress = findViewById<ProgressBar>(R.id.fileProgressBar)
fileProgress.visibility = View.GONE
val videoExoFile = findViewById<PlayerView>(R.id.videoExoFile)
videoExoFile.visibility = View.VISIBLE
exoPlayer = SimpleExoPlayer.Builder(this).build()
videoExoFile.player = exoPlayer;

val mediaItem: MediaItem = MediaItem.fromUri(infoModel.getFileUrl())
exoPlayer.setMediaItem(mediaItem);
exoPlayer.prepare()

exoPlayer.play()
}

private fun loadText() {
request = FuelService().getFileText(infoModel.getFileUrl())
.responseString() { _, _, result ->
when (result) {
is Result.Success -> {
Log.d("text", "text ${result.get()}")
textLiveData.postValue(result.get())
}
is Result.Failure -> {
Log.d("text", "error ${result.error.exception.message}")
textLiveData.postValue(result.error.exception.message)
}
}
}

textLiveData.observe(this, {
val fileProgress = findViewById<ProgressBar>(R.id.fileProgressBar)
val textFile = findViewById<TextView>(R.id.textFile)
val textScrollView = findViewById<ScrollView>(R.id.textScrollView)
fileProgress.visibility = View.GONE
textFile.text = it
textFile.visibility = View.VISIBLE
textScrollView.visibility = View.VISIBLE
})
}


override fun onBackPressed() {
if (this::exoPlayer.isInitialized) {
exoPlayer.release();
}
if (this::request.isInitialized) {
request.tryCancel()
}
super.onBackPressed()
}


override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (this::exoPlayer.isInitialized) {
exoPlayer.release();
}
if (this::request.isInitialized) {
request.tryCancel()
}
finish();
return super.onOptionsItemSelected(item)
}
}
76 changes: 76 additions & 0 deletions app/src/main/java/xo/william/pixeldrain/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package xo.william.pixeldrain

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.core.widget.doOnTextChanged
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.github.kittinunf.fuel.core.requests.tryCancel
import kotlinx.android.synthetic.main.activity_file_view.*
import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.android.synthetic.main.activity_login.sub_toolbar
import xo.william.pixeldrain.model.LoginResponse
import xo.william.pixeldrain.model.LoginViewModel
import xo.william.pixeldrain.repository.SharedRepository

class LoginActivity : AppCompatActivity() {

private var username = ""
private var password = ""

private lateinit var loginViewModel: LoginViewModel
private lateinit var sharedRepository: SharedRepository

override fun onCreate(savedInstanceState: Bundle?) {
sharedRepository = SharedRepository(this)

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
setSupportActionBar(sub_toolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
}

loginViewModel = ViewModelProvider(this).get(LoginViewModel::class.java)

userInput.doOnTextChanged { text, _, _, _ ->
username = text.toString()
loginButton.isEnabled = (username.isNotEmpty() && password.isNotEmpty())
}

passwordInput.doOnTextChanged { text, _, _, _ ->
password = text.toString()
loginButton.isEnabled = (username.isNotEmpty() && password.isNotEmpty())
}

loginButton.setOnClickListener {
loginButton.isEnabled = false
loginProgress.visibility = View.VISIBLE

loginViewModel.loginUser(username, password)
}

loginViewModel.loginResponse.observe(this,
{ response -> handleLoginResponse(response) })
}

private fun handleLoginResponse(response: LoginResponse) {
loginProgress.visibility = View.GONE
if (response.auth_key.isNotEmpty()) {
sharedRepository.saveToken(response.auth_key)
setResult(200)
finish()
} else {
loginButton.isEnabled = true
Toast.makeText(this, "Error: ${response.message}", Toast.LENGTH_LONG).show()
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
finish();
return super.onOptionsItemSelected(item)
}
}
Loading

0 comments on commit d43088c

Please sign in to comment.