Skip to content

Commit

Permalink
Merge branch 'master' into 2724-team-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 authored Nov 29, 2023
2 parents 954eafb + 0bcf397 commit d662c73
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 253 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1152
versionName "0.11.52"
versionCode 1164
versionName "0.11.64"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -119,7 +119,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
implementation 'com.github.bumptech.glide:glide:4.16.0'
kapt 'com.github.bumptech.glide:compiler:4.16.0'
implementation 'com.opencsv:opencsv:5.8'
implementation 'com.opencsv:opencsv:5.9'
implementation 'com.google.android.exoplayer:exoplayer:2.7.2'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'org.osmdroid:osmdroid-android:6.1.17'
Expand All @@ -131,12 +131,13 @@ dependencies {
implementation 'org.jetbrains:annotations:24.1.0'
implementation 'com.github.kizitonwose:CalendarView:1.1.0'
implementation "io.noties.markwon:editor:4.6.2"
implementation "io.noties.markwon:image:4.6.2"
implementation "androidx.core:core-ktx:1.12.0"
implementation "com.github.VaibhavLakhera:Circular-Progress-View:0.1.2"
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'com.applandeo:material-calendar-view:1.9.0'
implementation "androidx.work:work-runtime:2.8.1"
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.9.20"))
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.9.21"))
}
realm {
syncEnabled = true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<!-- <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>-->

<application
android:name=".MainApplication"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.ole.planet.myplanet.base

import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
Expand All @@ -19,23 +16,27 @@ import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatRatingBar
import androidx.core.content.FileProvider
import com.google.gson.JsonObject
import io.realm.RealmResults
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.base.PermissionActivity.hasInstallPermission
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.callback.OnRatingChangeListener
import org.ole.planet.myplanet.model.RealmMyLibrary
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.service.UserProfileDbHandler.KEY_RESOURCE_DOWNLOAD
import org.ole.planet.myplanet.service.UserProfileDbHandler.KEY_RESOURCE_OPEN
import org.ole.planet.myplanet.ui.course.AdapterCourses
import org.ole.planet.myplanet.ui.viewer.*
import org.ole.planet.myplanet.ui.viewer.AudioPlayerActivity
import org.ole.planet.myplanet.ui.viewer.CSVViewerActivity
import org.ole.planet.myplanet.ui.viewer.ImageViewerActivity
import org.ole.planet.myplanet.ui.viewer.MarkdownViewerActivity
import org.ole.planet.myplanet.ui.viewer.PDFReaderActivity
import org.ole.planet.myplanet.ui.viewer.TextFileViewerActivity
import org.ole.planet.myplanet.ui.viewer.VideoPlayerActivity
import org.ole.planet.myplanet.utilities.FileUtils
import org.ole.planet.myplanet.utilities.Utilities
import java.io.File
Expand All @@ -45,9 +46,9 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
var rating: TextView? = null
var ratingBar: AppCompatRatingBar? = null
lateinit var profileDbHandler: UserProfileDbHandler
private val INSTALL_UNKNOWN_SOURCES_REQUEST_CODE = 112
var hasInstallPermission = hasInstallPermission(MainApplication.context)
private var currentLibrary: RealmMyLibrary? = null
// private val INSTALL_UNKNOWN_SOURCES_REQUEST_CODE = 112
// var hasInstallPermission = hasInstallPermission(MainApplication.context)
// private var currentLibrary: RealmMyLibrary? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -145,7 +146,6 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
fun checkMoreFileExtensions(extension: String?, items: RealmMyLibrary) {
when (extension) {
"txt" -> openIntent(items, TextFileViewerActivity::class.java)
Expand All @@ -158,9 +158,8 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun installApk(items: RealmMyLibrary) {
currentLibrary = items
// currentLibrary = items
val directory = File(MainApplication.context.getExternalFilesDir(null).toString() + "/ole" + "/" + items.id)
if (!directory.exists()) {
if (!directory.mkdirs()) {
Expand All @@ -184,22 +183,22 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK

if (intent.resolveActivity(requireActivity().packageManager) != null) {
if (hasInstallPermission(MainApplication.context)) {
// if (hasInstallPermission(MainApplication.context)) {
startActivity(intent)
} else {
requestInstallPermission()
}
// } else {
// requestInstallPermission()
// }
} else {
Utilities.toast(activity,"No app to handle the installation")
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun requestInstallPermission() {
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
intent.data = Uri.parse("package:" + MainApplication.context.packageName)
startActivityForResult(intent, INSTALL_UNKNOWN_SOURCES_REQUEST_CODE)
}
// @RequiresApi(Build.VERSION_CODES.O)
// private fun requestInstallPermission() {
// val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
// intent.data = Uri.parse("package:" + MainApplication.context.packageName)
// startActivityForResult(intent, INSTALL_UNKNOWN_SOURCES_REQUEST_CODE)
// }

fun openFileType(items: RealmMyLibrary, videotype: String) {
val mimetype = Utilities.getMimeType(items.resourceLocalAddress)
Expand Down Expand Up @@ -299,22 +298,22 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
if (currentLibrary != null) {
installApk(currentLibrary!!)
currentLibrary = null
}
} else {
Utilities.toast(requireActivity(), getString(R.string.permissions_denied))
}
}
}
// @RequiresApi(Build.VERSION_CODES.O)
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// super.onActivityResult(requestCode, resultCode, data)
// if (requestCode == INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) {
// if (resultCode == Activity.RESULT_OK) {
// if (currentLibrary != null) {
// installApk(currentLibrary!!)
// currentLibrary = null
// }
// } else {
// Utilities.toast(requireActivity(), getString(R.string.permissions_denied))
// }
// }
// }

open fun handleBackPressed() {
requireActivity().onBackPressed()
}
// open fun handleBackPressed() {
// requireActivity().onBackPressed()
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void onReceive(Context context, Intent intent) {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MESSAGE_PROGRESS) && prgDialog != null) {
Download download = intent.getParcelableExtra("download");
if (!download.isFailed()) {
if (!download.failed) {
setProgress(download);
} else {
DialogUtils.showError(prgDialog, download.getMessage());
DialogUtils.showError(prgDialog, download.message);
}
}
}
Expand Down Expand Up @@ -171,11 +171,11 @@ public void notAvailable() {
}

public void setProgress(Download download) {
prgDialog.setProgress(download.getProgress());
if (!TextUtils.isEmpty(download.getFileName())) {
prgDialog.setTitle(download.getFileName());
prgDialog.setProgress(download.progress);
if (!TextUtils.isEmpty(download.fileName)) {
prgDialog.setTitle(download.fileName);
}
if (download.isCompleteAll()) {
if (download.completeAll) {
DialogUtils.showError(prgDialog, getString(R.string.all_files_downloaded_successfully));
onDownloadComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public boolean checkPermission(String strPermission) {
return result == PackageManager.PERMISSION_GRANTED;
}

public static boolean hasInstallPermission(android.content.Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return context.getPackageManager().canRequestPackageInstalls();
}
return true;
}
// public static boolean hasInstallPermission(android.content.Context context) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// return context.getPackageManager().canRequestPackageInstalls();
// }
// return true;
// }

public void checkUsagesPermission() {
if (!getUsagesPermission(this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MESSAGE_PROGRESS)) {
Download download = intent.getParcelableExtra("download");
if (onProgressChange != null) {
onProgressChange.onProgressChange(String.format("Downloading file %d/%d KB\n%d%% Completed.", download.getCurrentFileSize(), download.getTotalFileSize(), download.getProgress()));
onProgressChange.onProgressChange(String.format("Downloading file %d/%d KB\n%d%% Completed.", download.currentFileSize, download.totalFileSize, download.progress));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private void downloadFiled(String message) {
notificationManager.notify(0, notificationBuilder.build());
Download d = new Download();
completeAll = false;
d.setFailed(true);
d.setMessage(message);
d.failed = true;
d.message = message;
sendIntent(d);
stopSelf();
}
Expand All @@ -119,11 +119,11 @@ private void downloadFile(ResponseBody body) throws IOException {
int progress = (int) ((total * 100) / fileSize);
long currentTime = System.currentTimeMillis() - startTime;
Download download = new Download();
download.setFileName(FileUtils.getFileNameFromUrl(url));
download.setTotalFileSize(totalFileSize);
download.fileName = FileUtils.getFileNameFromUrl(url);
download.totalFileSize = totalFileSize;
if (currentTime > 1000 * timeCount) {
download.setCurrentFileSize((int) current);
download.setProgress(progress);
download.currentFileSize= (int) current;
download.progress = progress;
sendNotification(download);
timeCount++;
}
Expand Down Expand Up @@ -151,10 +151,10 @@ private void closeStreams(OutputStream output, InputStream bis) throws IOExcepti
}

private void sendNotification(Download download) {
download.setFileName("Downloading : " + FileUtils.getFileNameFromUrl(url));
download.fileName = "Downloading : " + FileUtils.getFileNameFromUrl(url);
sendIntent(download);
notificationBuilder.setProgress(100, download.getProgress(), false);
notificationBuilder.setContentText("Downloading file " + download.getCurrentFileSize() + "/" + totalFileSize + " KB");
notificationBuilder.setProgress(100, download.progress, false);
notificationBuilder.setContentText("Downloading file " + download.currentFileSize + "/" + totalFileSize + " KB");
notificationManager.notify(0, notificationBuilder.build());
}

Expand All @@ -167,12 +167,12 @@ private void sendIntent(Download download) {
private void onDownloadComplete() {
if (outputFile.length() > 0) changeOfflineStatus();
Download download = new Download();
download.setFileName(FileUtils.getFileNameFromUrl(url));
download.setFileUrl(url);
download.setProgress(100);
download.fileName = FileUtils.getFileNameFromUrl(url);
download.fileUrl = url;
download.progress = 100;
if (currentIndex == urls.size() - 1) {
completeAll = true;
download.setCompleteAll(true);
download.completeAll = true;
}
sendIntent(download);
notificationManager.cancel(0);
Expand Down
Loading

0 comments on commit d662c73

Please sign in to comment.