Skip to content

Commit

Permalink
v 0.7.0
Browse files Browse the repository at this point in the history
 - Major UI Changes with Modern UI 😍😍.
 - Faster Startup of ZeroNet 😁😁.
 - Individual Site Details for Popular Sites with Stats and useful functions 😘😘.
 - Update Minimum Android Support Version to API 21 (Android 5.0 Lollipop).
 - Add Site Shortcut to HomeScreen.
 - Added In-App Review so that you can give your feedback quickly.
- Several Bug Fixes and Improvements.

squash merge from this commit
e7601a6 to master
  • Loading branch information
canewsin committed Sep 20, 2020
1 parent 462ee78 commit f69e6a7
Show file tree
Hide file tree
Showing 44 changed files with 3,091 additions and 1,159 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ android {
defaultConfig.ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86_64'
}
}
dynamicFeatures = [":arm64", ":arm", ":common", ":x86", ":x86_64", ":nativelibs"]
dynamicFeatures = [":arm64", ":arm", ":common", ":x86", ":x86_64"]


}
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

<!-- android:name=".MyApplication"-->
<!-- android:name=".MyApplication"-->
<application
android:name=".MyApplication"
android:label="ZeroNet"
Expand Down
85 changes: 76 additions & 9 deletions android/app/src/main/kotlin/in/canews/zeronet/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package `in`.canews.zeronet

import android.annotation.SuppressLint
import android.app.Activity
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand All @@ -13,6 +18,9 @@ import android.util.Log
import androidx.annotation.NonNull
import androidx.core.app.ShareCompat
import androidx.core.content.FileProvider
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.play.core.splitinstall.SplitInstallManager
Expand Down Expand Up @@ -44,36 +52,47 @@ class MainActivity : FlutterActivity() {
private var splitInstallManager: SplitInstallManager? = null
private lateinit var result: MethodChannel.Result
private var mSessionId = -1
private var mLaunchShortcutUrl = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if(intent.getStringExtra("LAUNCH_SHORTCUT_URL") != null){
mLaunchShortcutUrl = intent.getStringExtra("LAUNCH_SHORTCUT_URL")
}
MethodChannel(flutterEngine?.dartExecutor, CHANNEL).setMethodCallHandler { call, result ->
when (call.method) {
"addToHomeScreen" -> addShortcutToHomeScreen(context, result,
call.argument("title"),call.argument("url"),
call.argument("logoPath")
)
"batteryOptimisations" -> getBatteryOptimizations(result)
"copyAssetsToCache" -> result.success(copyAssetsToCache())
"getAppInstallTime" -> getAppInstallTime(result)
"getAppLastUpdateTime" -> getAppLastUpdateTime(result)
"isBatteryOptimized" -> isBatteryOptimized(result)
"isPlayStoreInstall" -> result.success(isPlayStoreInstall(this))
"initSplitInstall" -> {
if (splitInstallManager == null)
splitInstallManager = LocallyDynamicSplitInstallManagerFactory.create(this)
result.success(true)
}
"uninstallModules" -> uninstallModules()
"isModuleInstallSupported" -> result.success(isModuleInstallSupported())
"isRequiredModulesInstalled" -> result.success(isRequiredModulesInstalled())
"copyAssetsToCache" -> result.success(copyAssetsToCache())
"launchZiteUrl" -> result.success(mLaunchShortcutUrl)
"moveTaskToBack" -> {
moveTaskToBack(true)
result.success(true)
}
"nativeDir" -> result.success(applicationInfo.nativeLibraryDir)
"nativePrint" -> {
Log.e("Flutter>nativePrint()",call.arguments())
}
"openJsonFile" -> openJsonFile(result)
"openZipFile" -> openZipFile(result)
"readJsonFromUri" -> readJsonFromUri(call.arguments.toString(), result)
"readZipFromUri" -> readZipFromUri(call.arguments.toString(), result)
"saveUserJsonFile" -> saveUserJsonFile(this, call.arguments.toString(), result)
"nativePrint" -> {
Log.e("Flutter>nativePrint()",call.arguments())
}
"moveTaskToBack" -> {
moveTaskToBack(true)
result.success(true)
}
"uninstallModules" -> uninstallModules()
}
}
}
Expand All @@ -95,6 +114,54 @@ class MainActivity : FlutterActivity() {
)
}

private fun addShortcutToHomeScreen(context: Context,mResult: MethodChannel.Result,
title:String?,url:String?,logoPath:String?) {
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
val shortcutInfoBuilder: ShortcutInfoCompat.Builder = ShortcutInfoCompat.Builder(context, title.toString())
.setIntent(
Intent(context, MainActivity::class.java)
.setAction(Intent.ACTION_MAIN)
.putExtra(
"LAUNCH_SHORTCUT_URL",
url
)
)
.setShortLabel(title.toString())
if (logoPath.toString().isNotEmpty()){
val image = File(logoPath.toString())
val bmOptions: BitmapFactory.Options = BitmapFactory.Options()
val bitmap: Bitmap = BitmapFactory.decodeFile(image.absolutePath, bmOptions)
shortcutInfoBuilder.setIcon(IconCompat.createWithBitmap(bitmap))
} else {
shortcutInfoBuilder.setIcon(IconCompat.createWithResource(context, R.drawable.logo))
}
val shortcutInfo: ShortcutInfoCompat = shortcutInfoBuilder.build()
val shortcutCallbackIntent: PendingIntent = PendingIntent.getBroadcast(context,
0,
Intent(context, MainActivity::class.java)
.putExtra("SHORTCUT_ADDED",true),
PendingIntent.FLAG_UPDATE_CURRENT)
ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, shortcutCallbackIntent.intentSender)
mResult.success(true)
} else {
// Shortcut is not supported by your launcher
}
}

private fun getAppInstallTime(result: MethodChannel.Result) {
val info = context.packageManager.getPackageInfo(context.packageName,0);
val field = PackageInfo::class.java.getField("firstInstallTime")
val timeStamp = field.getLong(info)
result.success(timeStamp.toString())
}

private fun getAppLastUpdateTime(result: MethodChannel.Result) {
val info = context.packageManager.getPackageInfo(context.packageName,0);
val field = PackageInfo::class.java.getField("lastUpdateTime")
val timeStamp = field.getLong(info)
result.success(timeStamp.toString())
}

private fun isPlayStoreInstall(context: Context): Boolean {
val validInstallers: List<String> = listOf("com.android.vending", "com.google.android.feedback")
val installer = context.packageManager.getInstallerPackageName(context.packageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import com.google.android.play.core.splitcompat.SplitCompatApplication
internal class MyApplication : SplitCompatApplication(){
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
SplitCompat.install(base)
SplitCompat.install(base!!)
}
}
1 change: 0 additions & 1 deletion android/nativelibs/.gitignore

This file was deleted.

26 changes: 0 additions & 26 deletions android/nativelibs/build.gradle

This file was deleted.

14 changes: 0 additions & 14 deletions android/nativelibs/src/main/AndroidManifest.xml

This file was deleted.

4 changes: 2 additions & 2 deletions android/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flutter.versionName=0.6.5
flutter.versionCode=4083
flutter.versionName=0.7.0
flutter.versionCode=4100
148 changes: 148 additions & 0 deletions lib/core/site/site.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import 'dart:convert';

import 'dart:io';

class Site {
String address;
String addressHash;
String addressSha1;
String addressShort;
int added;
String ajaxKey;
String authKey;
int bytesRecv;
int bytesSent;
Cache cache;
int downloaded;
int modified;
int optionalDownloaded;
Map<String, dynamic> optionalHelp;
bool own;
int peers;
List<String> permissions;
bool serving;
int size;
int sizeFilesOptional;
int sizeOptional;
String wrapperKey;

Site({
this.address,
this.addressHash,
this.addressSha1,
this.addressShort,
this.added,
this.ajaxKey,
this.authKey,
this.bytesRecv,
this.bytesSent,
this.cache,
this.downloaded,
this.modified,
this.optionalDownloaded,
this.optionalHelp,
this.own = false,
this.peers,
this.permissions,
this.serving = true,
this.size,
this.sizeFilesOptional,
this.sizeOptional,
this.wrapperKey,
});

Site pause() {
return this..serving = false;
}

Site resume() {
return this..serving = true;
}

Site.fromJson(Map<String, dynamic> jsonStr) {
added = jsonStr['added']?.toInt();
ajaxKey = jsonStr['ajax_key'];
authKey = jsonStr['auth_key'];
bytesRecv = jsonStr['bytes_recv'];
bytesSent = jsonStr['bytes_sent'];
cache = jsonStr['cache'] != null ? Cache.fromJson(jsonStr['cache']) : null;
downloaded = jsonStr['downloaded']?.toInt();
modified = jsonStr['modified']?.toInt();
optionalDownloaded = jsonStr['optional_downloaded'];
optionalHelp = jsonStr['optional_help'] != null
? json.decode(jsonStr['optional_help'])
: null;
own = jsonStr['own'];
peers = jsonStr['peers'];
permissions = jsonStr['permissions'].cast<String>();
serving = jsonStr['serving'];
size = jsonStr['size'];
sizeFilesOptional = jsonStr['size_files_optional'];
sizeOptional = jsonStr['size_optional'];
wrapperKey = jsonStr['wrapper_key'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['added'] = this.added;
data['ajax_key'] = this.ajaxKey;
data['auth_key'] = this.authKey;
data['bytes_recv'] = this.bytesRecv;
data['bytes_sent'] = this.bytesSent;
if (this.cache != null) {
data['cache'] = this.cache.toJson();
}
data['downloaded'] = this.downloaded;
data['modified'] = this.modified;
data['optional_downloaded'] = this.optionalDownloaded;
if (this.optionalHelp != null) {
data['optional_help'] = json.encode(this.optionalHelp);
}
data['own'] = this.own;
data['peers'] = this.peers;
data['permissions'] = this.permissions;
data['serving'] = this.serving;
data['size'] = this.size;
data['size_files_optional'] = this.sizeFilesOptional;
data['size_optional'] = this.sizeOptional;
data['wrapper_key'] = this.wrapperKey;
return data;
}
}

class Cache {
Map<String, dynamic> badFiles;
dynamic hashfield;
Map<String, dynamic> piecefields;

Cache({
this.badFiles,
this.hashfield,
this.piecefields,
});

Cache.fromJson(Map<String, dynamic> jsonStr) {
badFiles = jsonStr['bad_files'] != null ? jsonStr['bad_files'] : null;
hashfield = jsonStr['hashfield'];
piecefields =
jsonStr['piecefields'] != null ? jsonStr['piecefields'] : null;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.badFiles != null) {
data['bad_files'] = this.badFiles;
}
data['hashfield'] = this.hashfield;
if (this.piecefields != null) {
data['piecefields'] = this.piecefields;
}
return data;
}
}

extension SiteFileSystemExt on Site {
Site fromFile(File file) {
return Site.fromJson(json.decode(file.readAsStringSync()));
}
}
21 changes: 21 additions & 0 deletions lib/core/site/site_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'dart:convert';
import 'dart:io';

import 'package:zeronet/core/site/site.dart';

class SiteManager {
Map<String, Site> loadSitesFromFile(File file) {
Map<String, dynamic> content = json.decode(file.readAsStringSync());
Map<String, Site> sites = {};
for (var item in content.keys) {
sites[item] = Site.fromJson(content[item]);
}
return sites;
}

void saveSettingstoFile(File sitesFile, Map sitesData) {
if (sitesFile.existsSync()) {
sitesFile.writeAsStringSync(json.encode(sitesData));
}
}
}
Loading

0 comments on commit f69e6a7

Please sign in to comment.