Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa8e8d59 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Merge branch 'implement-app_request_form' into 'master'

Implement app request form

See merge request e/apps/apps!1
parents 7fb51290 1e9d9f67
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ android {
        applicationId "foundation.e.apps"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 2
        versionName "1.0.1"
        versionCode 3
        versionName "1.1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
+7 −24
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<!--
    Copyright (C) 2019  e Foundation

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="foundation.e.apps"
@@ -38,18 +20,19 @@
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="foundation.e.apps.MainActivity">
        <activity android:name=".settings.AppRequestActivity"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="foundation.e.apps.application.ApplicationActivity" />
        <activity android:name="foundation.e.apps.categories.category.CategoryActivity" />
        <activity android:name=".application.ApplicationActivity" />
        <activity android:name=".categories.category.CategoryActivity" />

        <service
            android:name="foundation.e.apps.applicationmanager.ApplicationManagerService"
            android:name=".applicationmanager.ApplicationManagerService"
            android:description="@string/service_description"
            android:exported="false" />

@@ -63,9 +46,9 @@
                android:resource="@xml/provider_paths" />
        </provider>

        <activity android:name="foundation.e.apps.application.ApplicationDescriptionActivity" />
        <activity android:name=".application.ApplicationDescriptionActivity" />
        <activity
            android:name="foundation.e.apps.application.ScreenshotsActivity"
            android:name=".application.ScreenshotsActivity"
            android:theme="@style/FullScreenTheme" />
    </application>

+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ class AppDetailRequest(private val id: String) {
    fun request(callback: (Error?, FullData?) -> Unit) {
        try {
            val url = Constants.BASE_URL + "apps?action=app_detail&id=$id"
            val urlConnection = Common.createConnection(url)
            val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
            val result = reader.readValue<Result>(urlConnection.inputStream)
            urlConnection.disconnect()
            callback.invoke(null, result.app)
+57 −0
Original line number Diff line number Diff line
/*
    Copyright (C) 2019  e Foundation

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.api

import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Error
import org.json.JSONObject
import java.net.HttpURLConnection

class AppRequestRequest {

    fun request(packageName: String, callback: (Error?) -> Unit) {
        val requestBody = JSONObject()
        requestBody.put("package_name", packageName)
        try {
            val url = Constants.BASE_URL + "app_suggestions"
            val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_POST)
            urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8")

            val outputStream = urlConnection.outputStream
            outputStream.write(requestBody.toString().toByteArray(charset("UTF-8")))
            outputStream.close()

            when (urlConnection.responseCode) {
                HttpURLConnection.HTTP_OK ->
                    callback.invoke(Error.NO_ERROR)
                HttpURLConnection.HTTP_BAD_REQUEST ->
                    callback.invoke(Error.INVALID_PACKAGE_NAME)
                HttpURLConnection.HTTP_NOT_ACCEPTABLE ->
                    callback.invoke(Error.PACKAGE_ALREADY_EXISTS)
                else ->
                    callback.invoke(Error.UNKNOWN)
            }

            urlConnection.disconnect()
        } catch (e: Exception) {
            e.printStackTrace()
            callback.invoke(Error.findError(e))
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class HomeRequest {
    fun request(callback: (Error?, HomeResult?) -> Unit) {
        try {
            val url = Constants.BASE_URL + "apps?action=list_home"
            val urlConnection = Common.createConnection(url)
            val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
            val result = reader.readValue<HomeResult>(urlConnection.inputStream)
            urlConnection.disconnect()
            callback.invoke(null, result)
Loading