This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
992 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,12 @@ | ||
# LBWallpaperForMuzei | ||
# LBWallpaper For Muzei | ||
[萝卜の图站](https://img.ijglb.com/) 随机手机壁纸 For [Muzei](https://muzei.co/) | ||
|
||
# 屏幕截图 | ||
<div> | ||
<img src="art/01.jpg" width="275" alt="screenshot 1"> | ||
<img src="art/02.jpg" width="275" alt="screenshot 2"> | ||
<img src="art/03.jpg" width="275" alt="screenshot 3"> | ||
</div> | ||
|
||
# 下载 | ||
Release:[https://github.com/ijglb/LBWallpaperForMuzei/releases](https://github.com/ijglb/LBWallpaperForMuzei/releases) |
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,2 @@ | ||
/build | ||
/release |
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,49 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.ijglb.muzei.lbwallpaper" | ||
minSdkVersion 19 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
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' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.3.2' | ||
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02' | ||
implementation 'com.google.android.material:material:1.1.0' | ||
implementation 'com.google.android.apps.muzei:muzei-api:3.4.0' | ||
implementation 'com.squareup.okhttp3:okhttp:4.9.0' | ||
implementation 'com.github.salomonbrys.kotson:kotson:2.5.0' | ||
implementation 'androidx.work:work-runtime-ktx:2.5.0-beta01' | ||
implementation 'androidx.preference:preference-ktx:1.1.1' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
} |
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 |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/ijglb/muzei/lbwallpaper/ExampleInstrumentedTest.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,24 @@ | ||
package com.ijglb.muzei.lbwallpaper | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.ijglb.muzei.lbwallpaper", appContext.packageName) | ||
} | ||
} |
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,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ijglb.muzei.lbwallpaper"> | ||
|
||
<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/Theme.LBWallpaperForMuzei" > | ||
|
||
<provider | ||
android:name=".LBWallpaperProvider" | ||
android:authorities="com.ijglb.muzei.lbwallpaper.LBWallpaperProvider" | ||
android:exported="true" | ||
android:label="@string/label" | ||
android:permission="com.google.android.apps.muzei.api.ACCESS_PROVIDER"> | ||
<intent-filter> | ||
<action android:name="com.google.android.apps.muzei.api.MuzeiArtProvider"/> | ||
</intent-filter> | ||
<meta-data | ||
android:name="settingsActivity" | ||
android:value="com.ijglb.muzei.lbwallpaper.SettingsActivity" /> | ||
<meta-data | ||
android:name="setupActivity" | ||
android:value="com.ijglb.muzei.lbwallpaper.SettingsActivity" /> | ||
</provider> | ||
|
||
<activity | ||
android:name=".SettingsActivity" | ||
android:exported="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/prefs_title" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:theme="@style/Theme.Muzei" /> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/ijglb/muzei/lbwallpaper/LBWallpaperProvider.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,34 @@ | ||
package com.ijglb.muzei.lbwallpaper | ||
|
||
import android.net.Uri | ||
import com.google.android.apps.muzei.api.provider.Artwork | ||
import com.google.android.apps.muzei.api.provider.MuzeiArtProvider | ||
|
||
class LBWallpaperProvider: MuzeiArtProvider() { | ||
companion object { | ||
private const val TAG = "LBWallpaperProvider" | ||
} | ||
/** | ||
* Callback method when the user has viewed all of the available artwork. This should be used | ||
* as a cue to load more artwork so that the user has a constant stream of new artwork. | ||
* | ||
* Muzei will always prefer to show unseen artwork, but will automatically cycle through all | ||
* of the available artwork if no new artwork is found (i.e., if you don't load new artwork | ||
* after receiving this callback). | ||
* | ||
* @param initial true when there is no artwork available, such as is the case when this is | ||
* the initial load of this MuzeiArtProvider. | ||
*/ | ||
override fun onLoadRequested(initial: Boolean) { | ||
if(initial){ | ||
setArtwork(Artwork( | ||
title = "ฅ╹ᗜ╹ฅ", | ||
token = "https://img.ijglb.com/content/uploadfile/202011/5a231604734407.png", | ||
persistentUri = Uri.parse("file:///android_asset/initial.png"), | ||
webUri = Uri.parse("https://img.ijglb.com/post/888") | ||
)) | ||
}else { | ||
context?.let { LBWallpaperWorker.enqueueLoad(it) } | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/ijglb/muzei/lbwallpaper/LBWallpaperWorker.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,64 @@ | ||
package com.ijglb.muzei.lbwallpaper | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.util.Log | ||
import androidx.work.Constraints | ||
import androidx.work.NetworkType | ||
import androidx.work.OneTimeWorkRequestBuilder | ||
import androidx.work.WorkManager | ||
import androidx.work.Worker | ||
import androidx.work.WorkerParameters | ||
import com.github.salomonbrys.kotson.fromJson | ||
import com.github.salomonbrys.kotson.string | ||
import com.google.android.apps.muzei.api.provider.Artwork | ||
import com.google.android.apps.muzei.api.provider.ProviderContract | ||
import com.google.gson.Gson | ||
import com.google.gson.JsonObject | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
|
||
class LBWallpaperWorker( | ||
context: Context, | ||
workerParams: WorkerParameters | ||
) : Worker(context, workerParams) { | ||
|
||
companion object { | ||
private const val TAG = "LBWallpaperWorker" | ||
|
||
internal fun enqueueLoad(context: Context) { | ||
val workManager = WorkManager.getInstance(context) | ||
workManager.enqueue(OneTimeWorkRequestBuilder<LBWallpaperWorker>() | ||
.setConstraints(Constraints.Builder() | ||
.setRequiredNetworkType(NetworkType.CONNECTED) | ||
.build()) | ||
.build()) | ||
} | ||
} | ||
|
||
override fun doWork(): Result { | ||
val providerClient = ProviderContract.getProviderClient( | ||
applicationContext, LBWallpaperProvider::class.java) | ||
val client = OkHttpClient() | ||
val request = Request.Builder() | ||
.url("https://img.ijglb.com/api.php?action=muzei") | ||
.build() | ||
try { | ||
val result = client.newCall(request).execute().body?.string() | ||
result?.let { | ||
Log.d(TAG,result) | ||
val json = Gson().fromJson<JsonObject>(it) | ||
val artwork = Artwork( | ||
title = json["title"].string, | ||
token = json["imgurl"].string, | ||
persistentUri = Uri.parse(json["imgurl"].string), | ||
webUri = Uri.parse(json["weburl"].string)) | ||
providerClient.addArtwork(artwork) | ||
} | ||
}catch(e: Exception){ | ||
e.printStackTrace() | ||
return Result.failure() | ||
} | ||
return Result.success() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/ijglb/muzei/lbwallpaper/SettingsActivity.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,60 @@ | ||
package com.ijglb.muzei.lbwallpaper | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.net.toUri | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import java.util.* | ||
|
||
class SettingsActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
// display the fragment as the main content. | ||
supportFragmentManager | ||
.beginTransaction() | ||
.replace(android.R.id.content, PrefsFragment()) | ||
.commit() | ||
setResult(Activity.RESULT_OK) | ||
} | ||
|
||
class PrefsFragment : PreferenceFragmentCompat() { | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
view.fitsSystemWindows = true | ||
} | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
addPreferencesFromResource(R.xml.preferences) | ||
|
||
// show correct version name & copyright year | ||
findPreference<Preference>(getText(R.string.pref_about_key))?.summary = getString( | ||
R.string.pref_about_summary, | ||
requireActivity().packageManager.getPackageInfo(requireActivity().packageName, 0).versionName, | ||
Calendar.getInstance().get(Calendar.YEAR)) | ||
// open browser | ||
findPreference<Preference>(getText(R.string.pref_link_key))?.setOnPreferenceClickListener { | ||
startActivity(Intent(Intent.ACTION_VIEW).apply { | ||
data = getString(R.string.pref_link_link).toUri() | ||
}) | ||
true | ||
} | ||
} | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
if (item.itemId == android.R.id.home) { | ||
onBackPressed() | ||
return true | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
|
||
} |
Oops, something went wrong.