Add StartServer activity

Create activity_start_server layout
Add textview and zim_list
Add menu button Host Books in MainActivity
Add values in strings.xml
This commit is contained in:
Adeel Zafar 2019-08-05 22:24:29 +05:00
parent 047dd4cd81
commit 5ae358c3d0
7 changed files with 118 additions and 17 deletions

View File

@ -69,6 +69,8 @@ dependencies {
implementation "androidx.collection:collection-ktx:1.1.0"
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion")
androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
@ -126,7 +128,6 @@ dependencies {
// Leak canary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "io.objectbox:objectbox-kotlin:$objectboxVersion"

View File

@ -10,7 +10,6 @@
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"/>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
@ -24,12 +23,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<!-- Devices with version >= Oreo need location permission to start/stop the hotspot -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Device with versions >= Pie need this permission -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <!-- Devices with version >= Oreo need location permission to start/stop the hotspot -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- Device with versions >= Pie need this permission -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
@ -41,7 +36,8 @@
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".webserver.StartServer">
</activity>
<activity
android:name=".splash.SplashActivity"
android:label="@string/app_name"
@ -56,7 +52,6 @@
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>
<activity
android:name=".main.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale"
@ -159,6 +154,7 @@
android:name=".zim_manager.ZimManageActivity"
android:label="@string/choose_file"
android:launchMode="singleTop">
<!-- TODO -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT"/>
@ -215,7 +211,6 @@
android:resource="@xml/provider_paths"/>
</provider>
<activity android:name=".intro.IntroActivity"/>
<activity android:name=".language.LanguageActivity"/>
<activity android:name=".history.HistoryActivity"/>
@ -231,4 +226,5 @@
</intent-filter>
</receiver>
</application>
</manifest>

View File

@ -124,6 +124,7 @@ import org.kiwix.kiwixmobile.utils.LanguageUtils;
import org.kiwix.kiwixmobile.utils.NetworkUtils;
import org.kiwix.kiwixmobile.utils.StyleUtils;
import org.kiwix.kiwixmobile.utils.files.FileUtils;
import org.kiwix.kiwixmobile.webserver.StartServer;
import org.kiwix.kiwixmobile.webserver.WebServerHelper;
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotService;
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
@ -946,6 +947,12 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
Intent intentSupportKiwix = new Intent(Intent.ACTION_VIEW, uriSupportKiwix);
intentSupportKiwix.putExtra(EXTRA_EXTERNAL_LINK, true);
openExternalUrl(intentSupportKiwix);
break;
case R.id.menu_host_books:
Intent intent = new Intent(MainActivity.this, StartServer.class);
startActivity(intent);
break;
case R.id.menu_wifi_hotspot:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -1911,6 +1918,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
menu.findItem(R.id.menu_random_article).setVisible(false);
menu.findItem(R.id.menu_searchintext).setVisible(false);
menu.findItem(R.id.menu_wifi_hotspot).setVisible(false);
menu.findItem(R.id.menu_host_books).setVisible(true);
} else {
menu.findItem(R.id.menu_read_aloud).setVisible(true);
menu.findItem(R.id.menu_home).setVisible(true);

View File

@ -0,0 +1,34 @@
package org.kiwix.kiwixmobile.webserver;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment;
public class StartServer extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_server);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ZimFileSelectFragment fragment = new ZimFileSelectFragment();
fragmentTransaction.add(R.id.frameLayoutServer, fragment);
fragmentTransaction.commit();
setUpToolbar();
}
private void setUpToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getString(R.string.menu_host_books));
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
}
}

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constraintLayoutId"
tools:context=".webserver.StartServer"
>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_constraintTop_toTopOf="parent"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</com.google.android.material.appbar.AppBarLayout>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAlignment="center"
android:text="@string/server_textview_default_message"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout2"
/>
<FrameLayout
android:id="@+id/frameLayoutServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:layout_editor_absoluteX="0dp"
></FrameLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -79,6 +79,11 @@
android:visible="false"
app:showAsAction="never"/>
<item
android:id="@+id/menu_host_books"
android:title="@string/menu_host_books"
app:showAsAction="never"/>
<item
android:id="@+id/menu_help"
android:title="@string/menu_help"

View File

@ -15,6 +15,7 @@
<string name="menu_read_aloud_stop">Stop reading aloud</string>
<string name="menu_support_kiwix">Support Kiwix</string>
<string name="menu_wifi_hotspot">Wifi Hotspot</string>
<string name="menu_host_books">Host Books</string>
<string name="save_media">Save Media</string>
<string name="save_media_error">An error occurred when trying to save the media!</string>
<string name="save_media_saved">Saved media as %s to Android/media/org.kiwix…/</string>
@ -31,6 +32,7 @@
<string name="hotspot_ssid_label">SSID : </string>
<string name="hotspot_pass_label">Pass : </string>
<string name="port_hint">8080</string>
<string name="server_textview_default_message">Select the files you wish to host on the server</string>
<string name="start_server_dialog_title">Start server</string>
<string name="start_server_dialog_message">You can now start the server using this ip address and port no.</string>
<string name="mobile_data_enabled">Warning: Mobile data enabled</string>