AleksandraLebedeva 1 سال پیش
والد
کامیت
b3b4218118

+ 77 - 0
app/src/main/java/com/example/test/AdapterMask.java

@@ -0,0 +1,77 @@
+package com.example.test;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.util.Base64;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.List;
+
+public  class AdapterMask extends BaseAdapter {
+
+    private Context mContext;
+    private List<DataModal> mListMask;
+
+    public AdapterMask(Context mContext, List<DataModal> listProduct)
+    {
+        this.mContext = mContext;
+        this.mListMask = listProduct;
+    }
+//List<DataModal> maskList;
+    @Override
+    public int getCount()
+    {
+        return mListMask.size();
+    }
+    @Override
+    public  Object getItem(int position)
+    {
+        return mListMask.get(position);
+    }
+
+    @Override
+    public long getItemId(int position)
+    {
+        return mListMask.get(position).getKod_teacher();
+    }
+
+    private Bitmap getUserImage(String encodeImg)
+    {
+        if(encodeImg != null && !encodeImg.equals("null"))
+        {
+            byte[] bytes = Base64.decode(encodeImg, Base64.DEFAULT);
+            return BitmapFactory.decodeByteArray(bytes, 0,bytes.length);
+        }
+        else
+        {
+            return BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher_foreground);
+        }
+    }
+
+    @Override
+    public View getView(int position, View view, ViewGroup parent)
+    {
+        View v = View.inflate(mContext, R.layout.mask, null);
+        TextView Fam = v.findViewById(R.id.Fam);
+        TextView Patronymic = v.findViewById(R.id.Patronymic);
+        TextView Subject = v.findViewById(R.id.Subject);
+        TextView Name = v.findViewById(R.id.Name);
+        ImageView Images = v.findViewById(R.id.image);
+
+        DataModal dataModal = mListMask.get(position);
+        Fam.setText(dataModal.getSurname());
+        Patronymic.setText(dataModal.getPatronymic());
+        Name.setText(dataModal.getName());
+        Subject.setText(dataModal.getSubject());
+
+        Images.setImageBitmap(getUserImage(dataModal.getImages()));
+
+        return  v;
+    }
+
+}

+ 6 - 4
app/src/main/java/com/example/test/Autorezation.java

@@ -1,5 +1,6 @@
 package com.example.test;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
@@ -25,10 +26,11 @@ public class Autorezation extends AppCompatActivity {
     public void Adm(View view)
     {
 
-        if(Log.getText().toString().matches(" "))
-        {
-
-        }
+        //if(Log.getText().toString().matches(" "))
+        //{
+            Intent intent = new Intent(this, MainActivity.class);
+            startActivity(intent);
+        //}
     }
 
 }

+ 63 - 46
app/src/main/java/com/example/test/DataModal.java

@@ -5,80 +5,82 @@ import android.os.Parcelable;
 
 public class DataModal implements Parcelable {
 
-    private  Integer Kod_teacher;
-    private String Name;
-    private String Surname;
-    private String Patronymic;
-    private String Subject;
-    private String Image;
+    Integer Kod_teacher;
+    String Name;
+    String Surname;
+    String Patronymic;
+    String Subject;
+    String Images;
 
-    public DataModal(Integer Kod_teacher, String Name,
-                     String Surname, String Patronymic,
-                     String Subject, String Image)
+
+    // для считывания
+    public DataModal (Integer Kod_teacher, String Name, String Surname,
+               String Patronymic, String Subject, String Images)
     {
         this.Kod_teacher = Kod_teacher;
         this.Name = Name;
         this.Surname = Surname;
         this.Patronymic = Patronymic;
         this.Subject = Subject;
-        this.Image = Image;
+        this.Images = Images;
     }
 
-    protected DataModal(Parcel in) {
-        Kod_teacher = in.readInt();
-        Name = in.readString();
-        Surname = in.readString();
-        Patronymic = in.readString();
-        Subject = in.readString();
-        Image = in.readString();
+    public  Integer getKod_teacher()
+    {
+        return Kod_teacher;
     }
-
-    public Integer getKod_teacher(){return Kod_teacher; }
-    public String getName(){return Name;}
-    public String getSurname(){return Surname;}
-    public String getPatronymic(){return Patronymic;}
-    public String getSubject(){return Subject;}
-    public String getImage(){return Image;}
-
-
-    public void  setKod_teacher(Integer Kod_teacher)
+    public  String getName()
+    {
+        return Name;
+    }
+    public  String getSurname()
+    {
+        return Surname;
+    }
+    public  String getPatronymic()
+    {
+        return Patronymic;
+    }
+    public  String getSubject()
+    {
+        return Subject;
+    }
+    public  String getImages()
+    {
+        return Images;
+    }
+    public  void setKod_teacher(Integer Kod_teacher)
     {
         this.Kod_teacher = Kod_teacher;
     }
-    public void  setName(String Name)
+    public  void setName(String Name)
     {
         this.Name = Name;
-    }
-    public void  setSurname(String Surname)
+    }public  void setSurname(String Surname)
     {
         this.Surname = Surname;
     }
-    public void  setPatronymic(String Patronymic)
+    public  void setPatronymic(String Patronymic)
     {
         this.Patronymic = Patronymic;
     }
-    public void  setSubject(String Subject)
+    public  void setSubject(String Subject)
     {
         this.Subject = Subject;
     }
-    public void  setImage(String Image)
+    public  void setImages(String Images)
     {
-        this.Image = Image;
+        this.Images = Images;
     }
 
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeInt(Kod_teacher);
-        dest.writeString(Name);
-        dest.writeString(Surname);
-        dest.writeString(Patronymic);
-        dest.writeString(Subject);
-        dest.writeString(Image);
-    }
 
-    @Override
-    public int describeContents() {
-        return 0;
+    protected DataModal(Parcel in) {
+        Kod_teacher = in.readInt();
+        Name = in.readString();
+        Surname = in.readString();
+        Patronymic = in.readString();
+        Subject = in.readString();
+        Images = in.readString();
     }
 
     public static final Creator<DataModal> CREATOR = new Creator<DataModal>() {
@@ -92,4 +94,19 @@ public class DataModal implements Parcelable {
             return new DataModal[size];
         }
     };
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel parcel, int i) {
+        parcel.writeInt(Kod_teacher);
+        parcel.writeString(Name);
+        parcel.writeString(Surname);
+        parcel.writeString(Patronymic);
+        parcel.writeString(Subject);
+        parcel.writeString(Images);
+    }
 }

+ 93 - 1
app/src/main/java/com/example/test/MainActivity.java

@@ -1,14 +1,106 @@
 package com.example.test;
 
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.widget.ListView;
+
 import androidx.appcompat.app.AppCompatActivity;
 
-import android.os.Bundle;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 public class MainActivity extends AppCompatActivity {
 
+
+
+    private  AdapterMask pAdapter;
+    String usl = "https://ngknn.ru:5001/NGKNN/лебедевааф/api/Teachers";
+List<DataModal> listlist= new ArrayList<>();
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
+
+
+        //ListList = findViewById(R.id.ListList);
+        ListView ivList = findViewById(R.id.ListList);
+pAdapter = new AdapterMask(MainActivity.this, listlist );
+        ivList.setAdapter(pAdapter);
+
+        List<String> list = new ArrayList<>();
+        list.add("Без сортировки");
+        list.add("Сортировка по имени");
+        list.add("Сортировка по фамилии");
+
+        List<String> list2 = new ArrayList<>();
+        list2.add("Без поиска");
+        list2.add("Имя");
+        list2.add("Фамилия");
+
+
+        new GetPr().execute();
+    }
+
+    private  class  GetPr extends AsyncTask<Void, Void, String>
+    {
+        @Override
+        protected String doInBackground(Void... voids) {
+            try {
+                URL url = new URL("https://ngknn.ru:5001/NGKNN/лебедевааф/api/Teachers");
+                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+            StringBuilder rez = new StringBuilder();
+            String line ="";
+            while ((line = reader.readLine())!= null)
+            {
+                rez.append(line);
+            }
+            return  rez.toString();
+            }
+            catch (IOException e) {
+                return  null;
+            }
+        }
+        @Override
+        protected void onPostExecute(String s)
+        {
+            super.onPostExecute(s);
+            try {
+                JSONArray tempArray = new JSONArray(s);
+                for(int i =0;i<tempArray.length();i++)
+                {
+                    JSONObject produstJSON= tempArray.getJSONObject(i);
+                   DataModal temp = new DataModal(
+                           produstJSON.getInt("Kod_teacher"),
+                           produstJSON.getString("Name"),
+                           produstJSON.getString("Surname"),
+                           produstJSON.getString("Patronymic"),
+                           produstJSON.getString("Subject"),
+                           produstJSON.getString("Images")
+                   );
+                    listlist.add(temp);
+                    pAdapter.notifyDataSetInvalidated();
+                }
+            }
+            catch (Exception e) {
+
+            }
+        }
+    }
+
+    public  void forBack ()
+    {
+        Intent intent = new Intent(MainActivity.this, Autorezation.class);
+        startActivity(intent);
+
     }
 }

+ 1 - 1
app/src/main/java/com/example/test/RetrofotAPI.java → app/src/main/java/com/example/test/RetrofitAPI.java

@@ -4,7 +4,7 @@ import retrofit2.Call;
 import retrofit2.http.Body;
 import retrofit2.http.POST;
 
-public interface RetrofotAPI {
+public interface RetrofitAPI {
     @POST("Users")
     Call<DataModal> createPost(@Body DataModal dataModal);
 }

+ 1 - 0
app/src/main/res/layout/activity_autorezation.xml

@@ -27,6 +27,7 @@
     </EditText>
     <Button
         android:id="@+id/btnAdm"
+        android:onClick="Adm"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="войти как автор"></Button>

+ 38 - 8
app/src/main/res/layout/activity_main.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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"
@@ -7,11 +7,18 @@
     tools:context=".MainActivity">
 
 
+
+    <LinearLayout
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical"
+    tools:ignore="MissingConstraints">
+
     <TextView
         style="@style/textstyle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_above="@+id/List"
+        android:layout_above="@+id/ListList"
         android:layout_alignParentStart="true"
         android:layout_alignParentTop="true"
         android:layout_alignParentEnd="true"
@@ -21,11 +28,34 @@
         android:layout_marginBottom="85dp"
         android:text="Заголовок"></TextView>
 
-    <ListView
-            android:id="@+id/List"
-            android:layout_width="match_parent"
-            android:layout_height="518dp"
+
+
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="назад"
+        android:gravity="center_vertical"
+        android:layout_alignParentBottom="true"
+        android:id="@+id/Back"
+        android:onClick="forBack">
+    </Button>
+
+        <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="очистить"
+            android:gravity="center_vertical"
             android:layout_alignParentBottom="true"
-            android:layout_marginBottom="16dp" />
+            android:id="@+id/Clear">
+        </Button>
+
+        <ListView
+            android:id="@+id/ListList"
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+
+            android:layout_alignParentBottom="true" />
+    </LinearLayout>
+
 
-</RelativeLayout>
+</androidx.constraintlayout.widget.ConstraintLayout>