commit ed190001290dd917472118e0dac6be04b236303e Author: Stepan Date: Mon Jun 2 06:30:23 2025 +0200 land_list diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d8f2491 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +land_list \ No newline at end of file diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..74dd639 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c54f4a6 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Land List + +> This is a school homework project. It is created for educational purposes only and is not intended for commercial use. + +The application was created to explore how an API retrieves JSON data from a server. + +## 📁 Main Direcories + +- [Main source code](app/src/main/java/com/example/land_list/) +- [layouts/](app/src/main/res/layout/) + +![result](readme_media/list.png) \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..28c9faa --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.land_list" + compileSdk = 35 + + defaultConfig { + applicationId = "com.example.land_list" + minSdk = 26 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} + +dependencies { + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) + implementation("com.android.volley:volley:1.2.1") +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/land_list/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/land_list/ExampleInstrumentedTest.java new file mode 100644 index 0000000..4434013 --- /dev/null +++ b/app/src/androidTest/java/com/example/land_list/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.land_list; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.land_list", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f0dbcac --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/land_list/HttpHandler.java b/app/src/main/java/com/example/land_list/HttpHandler.java new file mode 100644 index 0000000..5ecc972 --- /dev/null +++ b/app/src/main/java/com/example/land_list/HttpHandler.java @@ -0,0 +1,33 @@ +package com.example.land_list; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class HttpHandler { + + + public String getJsonFromUrl(String urlString) { + StringBuilder result = new StringBuilder(); + + try { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + result.append(line); + } + + reader.close(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + return result.toString(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/land_list/Land.java b/app/src/main/java/com/example/land_list/Land.java new file mode 100644 index 0000000..a644707 --- /dev/null +++ b/app/src/main/java/com/example/land_list/Land.java @@ -0,0 +1,27 @@ +package com.example.land_list; +public class Land { + String grad; + String ulica; + int broj; + int povrsina; + String tip; + int id; + String kvalitet; + String privatno; + String dugovanje; + int telefon; + + + public Land(String grad, String ulica, int broj, int povrsina, String tip, int id, String kvalitet, String privatno, String dugovanje, int telefon) { + this.grad = grad; + this.ulica = ulica; + this.broj = broj; + this.povrsina = povrsina; + this.tip = tip; + this.id = id; + this.kvalitet = kvalitet; + this.privatno = privatno; + this.dugovanje = dugovanje; + this.telefon = telefon; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/land_list/MainActivity.java b/app/src/main/java/com/example/land_list/MainActivity.java new file mode 100644 index 0000000..d6aa324 --- /dev/null +++ b/app/src/main/java/com/example/land_list/MainActivity.java @@ -0,0 +1,80 @@ +package com.example.land_list; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.widget.ListView; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; + +public class MainActivity extends AppCompatActivity { + ListView listLand; + ArrayList landList = new ArrayList<>(); + landAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + + listLand = findViewById(R.id.listLand); + adapter = new landAdapter(this, landList); + listLand.setAdapter(adapter); + + new FetchData().execute("https://people.vts.su.ac.rs/~sanjam/zemljiste.txt"); + } + + private class FetchData extends AsyncTask { + @Override + protected String doInBackground(String... urls) { + HttpHandler handler = new HttpHandler(); + return handler.getJsonFromUrl(urls[0]); + } + + @Override + protected void onPostExecute(String result) { + try { + JSONObject json = new JSONObject(result); + JSONArray zemljista = json.getJSONArray("zemljiste"); + + for (int i = 0; i < zemljista.length(); i++) { + JSONObject obj = zemljista.getJSONObject(i); + + JSONObject opis = obj.getJSONObject("Opis"); + JSONObject vlasnik = obj.getJSONObject("vlasnik"); + + Land land = new Land( + obj.getString("grad"), + obj.getString("ulica"), + obj.getInt("broj"), + + opis.getInt("povrsina"), + opis.getString("tip"), + opis.getInt("id"), + opis.getString("kvalitet"), + + vlasnik.getString("privatno"), + vlasnik.getString("dugovanje"), + vlasnik.getInt("telefon") + ); + + landList.add(land); + } + + adapter.notifyDataSetChanged(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/land_list/MainActivity2.java b/app/src/main/java/com/example/land_list/MainActivity2.java new file mode 100644 index 0000000..80d1402 --- /dev/null +++ b/app/src/main/java/com/example/land_list/MainActivity2.java @@ -0,0 +1,84 @@ +package com.example.land_list; + +import android.os.Bundle; +import android.widget.ListView; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.toolbox.JsonObjectRequest; +import com.android.volley.toolbox.Volley; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; + +public class MainActivity2 extends AppCompatActivity { + + ListView listLand; + ArrayList landList = new ArrayList<>(); + landAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main2); + + listLand = findViewById(R.id.listLand); + adapter = new landAdapter(this, landList); + listLand.setAdapter(adapter); + + RequestQueue queue = Volley.newRequestQueue(this); + String url = "https://people.vts.su.ac.rs/~sanjam/zemljiste.txt"; + + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( + Request.Method.GET, url, null, + response -> { + try { + JSONArray zemljista = response.getJSONArray("zemljiste"); + + for (int i = 0; i < zemljista.length(); i++) { + JSONObject obj = zemljista.getJSONObject(i); + JSONObject opis = obj.getJSONObject("Opis"); + JSONObject vlasnik = obj.getJSONObject("vlasnik"); + + Land land = new Land( + obj.getString("grad"), + obj.getString("ulica"), + obj.getInt("broj"), + + opis.getInt("povrsina"), + opis.getString("tip"), + opis.getInt("id"), + opis.getString("kvalitet"), + + vlasnik.getString("privatno"), + vlasnik.getString("dugovanje"), + vlasnik.getInt("telefon") + ); + + landList.add(land); + } + + adapter.notifyDataSetChanged(); + + } catch (Exception e) { + e.printStackTrace(); + } + }, + error -> { + error.printStackTrace(); + } + ); + + + queue.add(jsonObjectRequest); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/land_list/landAdapter.java b/app/src/main/java/com/example/land_list/landAdapter.java new file mode 100644 index 0000000..b78cf7d --- /dev/null +++ b/app/src/main/java/com/example/land_list/landAdapter.java @@ -0,0 +1,37 @@ +package com.example.land_list; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import java.util.ArrayList; + +public class landAdapter extends ArrayAdapter { + public landAdapter(Context context, ArrayList LandList){ + super(context,0,LandList); + } + + @NonNull + @Override + public View getView(int position, View convertView, @NonNull ViewGroup parent) { + Land s = getItem(position); + if (convertView == null) { + convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_land, parent, false); + } + TextView tvAddress = convertView.findViewById(R.id.adresa); + TextView tvInfo = convertView.findViewById(R.id.opisInfo); + TextView tvOwner = convertView.findViewById(R.id.vlasnikInfo); + + tvAddress.setText(s.grad + ", " + s.ulica + " " + s.broj); + tvInfo.setText("Tip: " + s.tip + " (" + s.povrsina + " m², " + s.kvalitet + ")"); + tvOwner.setText("Privatno: " + s.privatno + ", Dugovanje: " + s.dugovanje + ", Tel: " + s.telefon); + + return convertView; + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..571e7cc --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main2.xml b/app/src/main/res/layout/activity_main2.xml new file mode 100644 index 0000000..0933574 --- /dev/null +++ b/app/src/main/res/layout/activity_main2.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_item_land.xml b/app/src/main/res/layout/list_item_land.xml new file mode 100644 index 0000000..a041ea5 --- /dev/null +++ b/app/src/main/res/layout/list_item_land.xml @@ -0,0 +1,22 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..f8a8fc0 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..c8524cd --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..bac34f4 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + land_list + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..a45ec47 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,9 @@ + + + + +