Skip to content

Commit

Permalink
max task num
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Apr 19, 2020
1 parent 98721e2 commit 63ba8da
Show file tree
Hide file tree
Showing 20 changed files with 253 additions and 66 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppThemeBase">
<activity
android:name=".manager.ManagerSettingsActivity"
android:label="@string/title_activity_manager_settings"></activity>

<activity
android:name=".activity.ImgDActivity"
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/bugly/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcherep"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppThemeBase">
<activity
android:name=".manager.ManagerSettingsActivity"
android:label="@string/title_activity_manager_settings"></activity>

<provider
android:name="androidx.core.content.FileProvider"
Expand All @@ -32,12 +35,8 @@
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:theme="@android:style/Theme.Translucent" />

<activity android:name=".activity.BlockActivity"></activity>
<activity android:name=".activity.BlockActivity" />
<activity android:name=".activity.NovelActivity" />
<activity
android:name=".activity.ProgressActivity"
android:label="@string/title_activity_progress" />
<activity android:name=".activity.WebViewActivity" />
<activity
android:name=".activity.SettingActivity"
Expand All @@ -60,9 +59,9 @@
</activity>

<activity-alias
android:name=".md"
android:name=".normal"
android:enabled="false"
android:icon="@mipmap/ic_launchermd"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:targetActivity=".activity.HelloMActivity">
<intent-filter>
Expand All @@ -84,9 +83,9 @@
</intent-filter>
</activity-alias>
<activity-alias
android:name=".normal"
android:name=".md"
android:enabled="false"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/ic_launchermd"
android:label="@string/app_name"
android:targetActivity=".activity.HelloMActivity">
<intent-filter>
Expand Down Expand Up @@ -156,6 +155,7 @@
<activity android:name=".activity.HistoryMActivity" />
<activity android:name=".activity.UserShowActivity" />
<activity android:name=".activity.UserMActivity" />
<activity android:name=".manager.DownloadManagerActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BasicGridItem
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.bottomsheets.gridItems
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.files.folderChooser
import com.afollestad.materialdialogs.lifecycle.lifecycleOwner
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.perol.asdpl.pixivez.BuildConfig
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.databinding.DialogMeBinding
import com.perol.asdpl.pixivez.objects.Toasty
import com.perol.asdpl.pixivez.services.PxEZApp
import com.tencent.bugly.beta.Beta
import okhttp3.*
import java.io.File
import java.io.FilenameFilter
import java.io.IOException
import java.util.*

class SettingFragment : PreferenceFragmentCompat() {
private val storagePermissions = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

defaultComponent =
ComponentName(requireContext().packageName, "com.perol.asdpl.pixivez.normal") //拿到默认的组件
ComponentName(requireContext().packageName, "com.perol.asdpl.pixivez.normal")
testComponent =
ComponentName(requireContext().packageName, "com.perol.asdpl.pixivez.triangle")
mdComponent = ComponentName(requireContext().packageName, "com.perol.asdpl.pixivez.md")
Expand Down Expand Up @@ -193,7 +193,6 @@ class SettingFragment : PreferenceFragmentCompat() {
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)

if (requestCode == REQUEST_CODE_PERMISSIONS) {
if (requireContext().allPermissionsGranted(storagePermissions)) {
showDirectorySelectionDialog()
Expand All @@ -208,15 +207,19 @@ class SettingFragment : PreferenceFragmentCompat() {
}



override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) {
"me" -> {
// Toasty.info(PxEZApp.instance, "no browser found", Toast.LENGTH_SHORT).show()
try {
/* val uri = Uri.parse("https://music.163.com/song?id=1335514068&userid=32973424")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)*/

val binding = DialogMeBinding.inflate(layoutInflater)
MaterialDialog(requireContext(), BottomSheet()).show {
cornerRadius(16f)
customView(view = binding.root)
}



} catch (e: Exception) {

}
Expand Down Expand Up @@ -273,7 +276,7 @@ class SettingFragment : PreferenceFragmentCompat() {
val cr = File(activity?.filesDir, list[a])
string += cr.readText()
}
val dialogBuild = MaterialAlertDialogBuilder(activity!!)
val dialogBuild = MaterialAlertDialogBuilder(requireActivity())
dialogBuild.setMessage(string).setTitle("这是崩溃报告,如果遇到个别功能闪退,请将此报告反馈给开发者")
.setPositiveButton(android.R.string.ok) { _, _ ->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import com.arialyy.annotations.Download
Expand All @@ -25,7 +24,10 @@ import com.perol.asdpl.pixivez.activity.PictureActivity
import com.perol.asdpl.pixivez.databinding.DownLoadManagerFragmentBinding
import com.perol.asdpl.pixivez.databinding.ItemDownloadTaskBinding
import com.perol.asdpl.pixivez.services.IllustD
import com.perol.asdpl.pixivez.services.PxEZApp
import com.perol.asdpl.pixivez.services.Works
import org.jetbrains.annotations.NotNull
import java.io.File


class DownloadTaskAdapter() :
Expand All @@ -38,22 +40,37 @@ class DownloadTaskAdapter() :
}
this.setOnItemLongClickListener { adapter, view, position ->
val item = data[position]
val illust = objectMapper.readValue(item.str, IllustD::class.java)
val illustD = objectMapper.readValue(item.str, IllustD::class.java)
MaterialDialog(context).show {
title(text = illust.title)
title(text = illustD.title)
listItems(R.array.download_task_choice) { _, index, string ->
when (index) {
0 -> {
Aria.download(context).load(data[position].id).stop()
val fileName = item.fileName
val targetPath =
"${PxEZApp.instance.cacheDir}${File.separator}${fileName}"
Aria.download(PxEZApp.instance)
.load(item.url) //读取下载地址
.setFilePath(targetPath) //设置文件保存的完整路径
.ignoreFilePathOccupy()
.setExtendField(Works.mapper.writeValueAsString(illustD))
.option(Works.option)
.create()

}
1 -> {
Aria.download(context).load(data[position].id).resume()
Aria.download(context).load(data[position].id).stop()
}
2 -> {
Aria.download(context).load(data[position].id).resume()
}
3 -> {
Aria.download(context).load(data[position].id).cancel(true)
}
}
val taskList = Aria.download(this).taskList
if (taskList?.isNotEmpty() == true)
this@DownloadTaskAdapter.setNewData(taskList.asReversed())
}
}
true
Expand Down Expand Up @@ -183,6 +200,7 @@ class DownLoadManagerFragment : Fragment() {
fun onTaskFail(task: DownloadTask) {
refreshSingle(task)
}

companion object {
fun newInstance() = DownLoadManagerFragment()
}
Expand Down Expand Up @@ -219,7 +237,8 @@ class DownLoadManagerFragment : Fragment() {
override fun onResume() {
super.onResume()
val taskList = Aria.download(this).taskList
downloadTaskAdapter.setNewData(taskList)
if (taskList?.isNotEmpty() == true)
downloadTaskAdapter.setNewData(taskList.asReversed())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,39 @@ package com.perol.asdpl.pixivez.manager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.arialyy.aria.core.Aria
import com.perol.asdpl.pixivez.R
import kotlinx.android.synthetic.main.activity_download_manager.*


class DownloadManagerActivity : AppCompatActivity() {
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_download_manager, menu)
return true

}

override fun onOptionsItemSelected(item: MenuItem): Boolean {

when (item.itemId) {
R.id.action_settings -> {

startActivity(Intent(this, ManagerSettingsActivity::class.java))
}
R.id.action_resume -> {
Aria.download(this).resumeAllTask()
}
R.id.action_cancel -> {
Aria.download(this).removeAllTask(false);
}

}
return super.onOptionsItemSelected(item)

}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.perol.asdpl.pixivez.manager

import android.content.res.Configuration
import android.os.Bundle
import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
import com.arialyy.aria.core.Aria
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.activity.RinkActivity
import kotlinx.android.synthetic.main.settings_activity.*

class ManagerSettingsActivity : RinkActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.settings_activity)
setSupportActionBar(toolbar)
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, SettingsFragment())
.commit()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(false)
toolbar.setNavigationOnClickListener { finish() }

}


class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
findPreference<ListPreference>("max_task_num")!!.setOnPreferenceChangeListener { preference, newValue ->
Aria.get(requireActivity()).downloadConfig.apply {
maxTaskNum = (newValue as String).toInt()
}
true
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
}
}
}
14 changes: 4 additions & 10 deletions app/src/main/java/com/perol/asdpl/pixivez/services/PxEZApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ class PxEZApp : Application() {
}
super.onCreate()
pre = PreferenceManager.getDefaultSharedPreferences(this)

Aria.init(this)
Aria.download(this).register()
// Aria.get(this).appConfig.logLevel= ALog.LOG_CLOSE
Aria.get(this).downloadConfig.apply {
maxTaskNum = pre.getString("max_task_num", "2")!!.toInt()
}
Aria.download(this).removeAllTask(true)
instance = this
AppCompatDelegate.setDefaultNightMode(
Expand Down Expand Up @@ -122,30 +124,22 @@ class PxEZApp : Application() {
Bugly.init(this, "1a2d5c746f", BuildConfig.DEBUG)
registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
// Logger.t(TAG).v("${activity.simpleName}: onActivityCreated")

ActivityCollector.collect(activity)
}

override fun onActivityStarted(activity: Activity) {
// Logger.t(TAG).v("${activity.simpleName}: onActivityStarted")
}

override fun onActivityResumed(activity: Activity) {
// Logger.t(TAG).v("${activity.simpleName}: onActivityResumed")
}

override fun onActivityPaused(activity: Activity) {
// Logger.t(TAG).v("${activity.simpleName}: onActivityPaused")
}

override fun onActivityStopped(activity: Activity) {
// Logger.t(TAG).v("${activity.simpleName}: onActivityStopped")
}

override fun onActivityDestroyed(activity: Activity) {
// Logger.t(TAG).v("${activity.simpleName}: onActivityDestroyed")

ActivityCollector.discard(activity)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_download_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:id="@+id/toolbar"
app:titleTextColor="?android:attr/textColorPrimaryInverse"
android:theme="@style/MyToolbar"
android:background="?attr/colorPrimary"
app:title="@string/download_progress"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/layout/dialog_me.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

</data>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="160dp" />

<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>

</layout>
Loading

0 comments on commit 63ba8da

Please sign in to comment.