Giter Club home page Giter Club logo

oss_project's Introduction

OSS_Project

채팅 앱 오픈소스를 개선하고 개선사항을 기록합니다.


ADD Function (MessageAdapterList.java)

   public MESSAGE getMessage(int idx) throws Exception {
        if(idx >= 0)
            return (MESSAGE) items.get(idx);
        else
            throw new Exception("Wrong Index.");

    }

    public MESSAGE getMessage(String content) throws Exception{
        for(Wrapper item : items){
            MESSAGE message = (MESSAGE) item;

            if(message.equals(message)){
                return (MESSAGE) items.get(0);
            }
        }

        return null;
    }

ADD Swipe Interface (Utility Expension)

public interface SetOnClickItemListener {

    public void onDeleteClick(DialogsListAdapter.BaseDialogViewHolder holder, View view, String itemId, int getAdapterPosition);
}

DialogViewHolder.class ADD method

        public void setOnItemClickListener(SetOnClickItemListener listener) {
            this.listener = listener;
        }

DialogViewHolder.class Listener MVC Pattern

 deleteLayout.setOnClickListener(view -> {
                if(listener != null){
                    listener.onDeleteClick((BaseDialogViewHolder)DialogViewHolder.this, view, dialog.getId(), getAdapterPosition());
                }
            });

DefaultDialogActivity.java Attach Listener

     dialogsAdapter.setOnItemClickListener(new SetOnClickItemListener() {
            @Override
            public void onDeleteClick(DialogsListAdapter.BaseDialogViewHolder holder, View view, String itemId, int getAdapterPosition) {
                dialogsAdapter.deleteById(itemId);
            }
        });

DialogsListAdapter - deleteById() 시간 복잡도 개선

Before O(n)

    public void deleteById(String id) {
        for (int i = 0; i < items.size(); i++) {
            if (items.get(i).getId().equals(id)) {
                items.remove(i);
                notifyItemRemoved(i);
            }
        }
    }



Modify DTO and related methods

After O(logn)

 public void deleteById(int id) {
        int idx = binarySerach(id, 0, items.size());
        items.remove(idx);
        notifyItemRemoved(idx);
    }


    public int binarySerach(int key, int low, int high){
        int mid;

        if(low <= high) {
            mid = (low + high) / 2;
            int cur = items.get(mid).getId();

            if(key == cur) {
                return mid;
            } else if(key < cur) {
                return binarySerach(key ,low, mid-1);
            } else {
                return binarySerach(key, mid+1, high);
            }
        }

        throw new IndexOutOfBoundsException("Invalidate Key");

    }

Fix to load avatar image bug

The demo app has a bug that does not load avatar images.
Because avatar image use http url.
Therefore, it should be specified in the manifest file as follows.

    <application
        ...
        android:usesCleartextTraffic="true">

Security

Information exposure through an error message

e.printStackTrace(); -> System.out.println(e);

Send Album image

Before the improvement, the source could only send the image url uploaded to the server,
but after the improvement, the image can be selected from the album and sent immediately.

In addition, the cropper function has been added to edit the selected image in the album.

Change ImageLoader interface

void loadImage(ImageView imageView, @Nullable String url, @Nullable Object payload, @Nullable Bitmap bitmap);

Change Image class and Add getImageBitmap() Method in Message class

  public Bitmap getImageBitmap() {return image == null ? null : image.bitmap;}

   public static class Image {

        private String url;
        private Bitmap bitmap;

        public Image(String url) {
            this.url = url;
        }
        public Image(Bitmap bitmap) {this.bitmap = bitmap; }
    }

Change getContentViewType Method in MessageHoder.class

    private short getContentViewType(IMessage message) {
        if (message instanceof MessageContentType.Image
                && ((MessageContentType.Image) message).getImageUrl() != null
                || ((MessageContentType.Image) message).getImageBitmap() != null) {
            return VIEW_TYPE_IMAGE_MESSAGE;
        }

Change to ImageLoader Listener in Activity

        imageLoader = new ImageLoader() {
            @Override
            public void loadImage(ImageView imageView, @Nullable String url, @Nullable Object payload, @Nullable Bitmap bitmap) {
                if(url == null)
                    imageView.setImageBitmap(bitmap);
                else
                     Picasso.get().load(url).into(imageView);

            }
        };

Change to onBind() Method in MessageHolders.class

  @Override
        public void onBind(MESSAGE message) {
            super.onBind(message);
            if (image != null && imageLoader != null) {
                imageLoader.loadImage(image, message.getImageUrl(), getPayloadForImageLoader(message), message.getImageBitmap());
            }

            if (imageOverlay != null) {
                imageOverlay.setSelected(isSelected());
            }
        }

ETC Commit Log

oss_project's People

Contributors

sey2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.