mirror of https://github.com/NekoX-Dev/NekoX.git
Drop CDNDrive support
This commit is contained in:
parent
159ced5544
commit
dac6bc4003
|
@ -104,6 +104,7 @@ public class AboutLinkCell extends FrameLayout {
|
|||
}
|
||||
stringBuilder = new SpannableStringBuilder(oldText);
|
||||
MessageObject.addLinks(false, stringBuilder, false, false, !parseLinks);
|
||||
Emoji.replaceEmoji(stringBuilder, Theme.profile_aboutTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
||||
if (TextUtils.isEmpty(value)) {
|
||||
valueTextView.setVisibility(GONE);
|
||||
} else {
|
||||
|
|
|
@ -68,6 +68,13 @@ public class TextDetailCell extends FrameLayout {
|
|||
setWillNotDraw(!needDivider);
|
||||
}
|
||||
|
||||
public void setTextWithEmojiAndValue(String text, CharSequence value, boolean divider) {
|
||||
textView.setText(Emoji.replaceEmoji(text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
|
||||
valueTextView.setText(value);
|
||||
needDivider = divider;
|
||||
setWillNotDraw(!divider);
|
||||
}
|
||||
|
||||
public void setContentDescriptionValueFirst(boolean contentDescriptionValueFirst) {
|
||||
this.contentDescriptionValueFirst = contentDescriptionValueFirst;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import cn.hutool.http.HttpRequest;
|
|||
import cn.hutool.http.HttpUtil;
|
||||
import tw.nekomimi.nekogram.utils.FileUtil;
|
||||
import tw.nekomimi.nkmr.CellGroup;
|
||||
import tw.nekomimi.nkmr.MiniCDNDrive;
|
||||
import tw.nekomimi.nkmr.NekomuraConfig;
|
||||
import tw.nekomimi.nkmr.NekomuraUtil;
|
||||
import tw.nekomimi.nkmr.cells.NekomuraTGSelectBox;
|
||||
|
@ -69,7 +68,7 @@ public class InternalUpdater {
|
|||
private static class NekoXAPK {
|
||||
String name;
|
||||
String sha1;
|
||||
String[] urls; // https://t.me/xxx or bdex://xxx
|
||||
String[] urls; // https://t.me/xxx or bdex://xxx, bdex removed
|
||||
}
|
||||
|
||||
private static ApkMetadata matchBuild(ApkMetadata[] apks) {
|
||||
|
@ -132,7 +131,6 @@ public class InternalUpdater {
|
|||
|
||||
// match apk urls. these can be empty.
|
||||
String urlChannel = "";
|
||||
String urlCDNDrive = "";
|
||||
String sha1 = "";
|
||||
try {
|
||||
final String newBody = HttpUtil.get("https://api.github.com/repos/NekoX-Dev/updates/contents/" + release.name + ".txt?ref=main");
|
||||
|
@ -147,7 +145,6 @@ public class InternalUpdater {
|
|||
sha1 = napk.sha1;
|
||||
for (String url : napk.urls) {
|
||||
if (url.startsWith("https://t.me/")) urlChannel = url;
|
||||
if (url.startsWith("bdex://")) urlCDNDrive = url;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -157,7 +154,6 @@ public class InternalUpdater {
|
|||
}
|
||||
|
||||
String finalsha1 = sha1;
|
||||
String finalUrlCDNDrive = urlCDNDrive;
|
||||
String finalUrlChannel = urlChannel;
|
||||
ReleaseMetadata finalRelease = release;
|
||||
|
||||
|
@ -180,7 +176,7 @@ public class InternalUpdater {
|
|||
builder.setPositiveButton(LocaleController.getString("VersionUpdateConfirm", R.string.VersionUpdateConfirm), (dialog, which) -> {
|
||||
showSelectDownloadSource(ctx, apk != null ? apk.name : finalRelease.name,
|
||||
apk != null ? apk.browser_download_url : finalRelease.html_url,
|
||||
finalUrlChannel, finalUrlCDNDrive, finalsha1);
|
||||
finalUrlChannel, finalsha1);
|
||||
});
|
||||
builder.setNeutralButton(LocaleController.getString("VersionUpdateIgnore", R.string.VersionUpdateIgnore), (dialog, which) -> NekoXConfig.setIgnoredUpdateTag(finalRelease.name));
|
||||
builder.setNegativeButton(LocaleController.getString("VersionUpdateNotNow", R.string.VersionUpdateNotNow), (dialog, which) -> NekoXConfig.setNextUpdateCheck(System.currentTimeMillis() / 1000 + 3 * 24 * 3600));
|
||||
|
@ -193,7 +189,7 @@ public class InternalUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
public static void showSelectDownloadSource(Context ctx, String title, String browser_download_url, String urlChannel, String urlCDNDrive, String sha1) {
|
||||
public static void showSelectDownloadSource(Context ctx, String title, String browser_download_url, String urlChannel, String sha1) {
|
||||
CellGroup nkmrCells = new CellGroup(null);
|
||||
|
||||
nkmrCells.callBackSettingsChanged = ((k, v) -> {
|
||||
|
@ -205,45 +201,12 @@ public class InternalUpdater {
|
|||
case 1:
|
||||
Browser.openUrl(ctx, urlChannel);
|
||||
break;
|
||||
case 2:
|
||||
AlertDialog progressDialog = new AlertDialog(ctx, 2);
|
||||
progressDialog.setTitle(title);
|
||||
progressDialog.setCanCacnel(false);
|
||||
progressDialog.show();
|
||||
try {
|
||||
File f = new File(ApplicationLoader.getDataDirFixed(), "cache/new.apk");
|
||||
f.createNewFile();
|
||||
MiniCDNDrive.INSTANCE.Download(f, urlCDNDrive, (percent) -> {
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
progressDialog.setProgress(percent);
|
||||
});
|
||||
}, () -> {
|
||||
progressDialog.dismiss();
|
||||
|
||||
try {
|
||||
if (NekomuraUtil.calcSHA1(f).equals(sha1)) {
|
||||
openApkInstall((Activity) ctx, f);
|
||||
} else {
|
||||
Toast.makeText(ctx, "Checksum mismatch!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
Toast.makeText(ctx, LocaleController.getString("DownloadFailed") + e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
progressDialog.dismiss();
|
||||
FileLog.e(e);
|
||||
Toast.makeText(ctx, LocaleController.getString("DownloadFailed") + e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
ArrayList<String> sources = new ArrayList<>();
|
||||
sources.add("Github Release"); // base of Current
|
||||
if (!urlChannel.isEmpty()) sources.add("Telegram Channel");
|
||||
if (!urlCDNDrive.isEmpty()) sources.add("CDN");
|
||||
|
||||
String[] sources_ = new String[sources.size()];
|
||||
sources.toArray(sources_);
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
package tw.nekomimi.nkmr
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import com.google.gson.Gson
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import java.io.*
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.math.roundToInt
|
||||
import android.graphics.Color
|
||||
import org.telegram.messenger.FileLog
|
||||
import java.nio.charset.Charset
|
||||
|
||||
|
||||
object MiniCDNDrive {
|
||||
|
||||
data class metaJSON(
|
||||
var time: Long = 0,
|
||||
var filename: String,
|
||||
var size: Long = 0,
|
||||
var sha1: String,
|
||||
var block: Array<metaJSON_Block>,
|
||||
)
|
||||
|
||||
data class metaJSON_Block(
|
||||
var size: Long = 0,
|
||||
var sha1: String,
|
||||
var url: String
|
||||
)
|
||||
|
||||
interface CallbackPercent {
|
||||
fun callbackPercent(percent: Int);
|
||||
}
|
||||
|
||||
fun Download(f: File, metaURL: String, callbackPercent: CallbackPercent, callbackFinished: Runnable) {
|
||||
thread {
|
||||
var output = FileOutputStream(f, false)
|
||||
val client = OkHttpClient();
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(meta2Real(metaURL))
|
||||
.build()
|
||||
val response = client.newCall(request).execute()
|
||||
val data = readPhotoBytes(response.body!!.bytes())
|
||||
|
||||
val meta = Gson().fromJson(String(data, Charset.forName("UTF-8")), metaJSON::class.java)
|
||||
|
||||
var counter = 0
|
||||
for (block in meta.block) {
|
||||
lateinit var data2: ByteArray
|
||||
val try_max = 3
|
||||
|
||||
for (i in 0 until try_max) {
|
||||
try {
|
||||
val url = block.url.replace("http://", "https://")
|
||||
|
||||
val request2 = Request.Builder()
|
||||
.url(url)
|
||||
.build()
|
||||
val response2 = client.newCall(request2).execute()
|
||||
data2 = readPhotoBytes(response2.body!!.bytes())
|
||||
break
|
||||
} catch (e: Exception) {
|
||||
if (i == try_max - 1) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
output.write(data2)
|
||||
|
||||
//TODO progress
|
||||
counter++
|
||||
callbackPercent.callbackPercent((counter * 100.0 / meta.block.size).roundToInt())
|
||||
}
|
||||
|
||||
output.close()
|
||||
callbackFinished.run()
|
||||
}
|
||||
}
|
||||
|
||||
fun meta2Real(meta: String): String {
|
||||
val regexp = Regex("bdex://([a-fA-F0-9]{40})")
|
||||
val matches = regexp.find(meta)!!
|
||||
|
||||
return "https://i0.hdslb.com/bfs/album/${matches.groupValues[1]}.png"
|
||||
}
|
||||
|
||||
fun readPhotoBytes(input: ByteArray): ByteArray {
|
||||
val img = BitmapFactory.decodeByteArray(input, 0, input.size)
|
||||
|
||||
val buf = ArrayList<Byte>()
|
||||
|
||||
for (y in 0 until img.width) {
|
||||
for (x in 0 until img.height) {
|
||||
val colour: Int = img.getPixel(x, y)
|
||||
buf.add(Color.red(colour).toByte())
|
||||
buf.add(Color.green(colour).toByte())
|
||||
buf.add(Color.blue(colour).toByte())
|
||||
}
|
||||
}
|
||||
|
||||
val buf1 = buf.toByteArray()
|
||||
val length = buf1.readUInt32LE(0).toInt()
|
||||
|
||||
return buf1.copyOfRange(4, 4 + length)
|
||||
}
|
||||
|
||||
private fun ByteArray.readUInt32LE(offset: Int = 0): Long {
|
||||
return (((this[offset + 3].toInt() and 0xFF).toLong() shl 24) or
|
||||
((this[offset + 2].toInt() and 0xFF).toLong() shl 16) or
|
||||
((this[offset + 1].toInt() and 0xFF).toLong() shl 8) or
|
||||
(this[offset].toInt() and 0xFF).toLong())
|
||||
}
|
||||
|
||||
}
|
|
@ -43,7 +43,7 @@ public class NekomuraConfig {
|
|||
public static ConfigItem largeAvatarInDrawer = addConfig("AvatarAsBackground", configTypeInt, 0); // 0:TG Default 1:NekoX Default 2:Large Avatar
|
||||
public static ConfigItem unreadBadgeOnBackButton = addConfig("unreadBadgeOnBackButton", configTypeBool, false);
|
||||
public static ConfigItem customPublicProxyIP = addConfig("customPublicProxyIP", configTypeString, "");
|
||||
public static ConfigItem update_download_soucre = addConfig("update_download_soucre", configTypeInt, 0); // 0: Github 1: Channel 2:CDNDrive
|
||||
public static ConfigItem update_download_soucre = addConfig("update_download_soucre", configTypeInt, 0); // 0: Github 1: Channel 2:CDNDrive, removed
|
||||
public static ConfigItem useCustomEmoji = addConfig("useCustomEmoji", configTypeBool, false);
|
||||
public static ConfigItem repeatConfirm = addConfig("repeatConfirm", configTypeBool, false);
|
||||
public static ConfigItem disableInstantCamera = addConfig("DisableInstantCamera", configTypeBool, false);
|
||||
|
|
Loading…
Reference in New Issue